Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'from:addr:timgolden.me.uk': 0.09; 'from:name:tim golden': 0.09; 'i.e.,': 0.09; 'message-id:@timgolden.me.uk': 0.09; 'say)': 0.09; 'storing': 0.09; 'subject:keys': 0.09; 'tuple': 0.09; 'meaningful': 0.13; 'users,': 0.13; 'def': 0.14; 'concepts.': 0.16; 'key?': 0.16; 'pythonic': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject: \n ': 0.16; 'subject:Was': 0.16; 'subject:arrays': 0.16; 'wrote:': 0.18; 'say,': 0.19; '(which': 0.19; 'structure': 0.23; 'dictionary': 0.23; 'header:In-Reply-To:1': 0.23; 'subject:]': 0.28; 'preferences': 0.28; 'books': 0.28; 'clear,': 0.30; 'if,': 0.30; 'tjg': 0.30; 'list': 0.32; 'sort': 0.32; 'to:addr:python-list': 0.32; 'header:User-Agent:1': 0.33; 'probably': 0.34; 'another.': 0.34; 'was,': 0.34; 'things': 0.35; "what's": 0.35; 'subject:/': 0.35; 'question': 0.35; 'useful': 0.36; 'clearly': 0.36; 'example,': 0.36; 'depend': 0.36; 'another': 0.36; 'doing': 0.37; 'using': 0.37; 'could': 0.38; 'easier': 0.38; 'received:192': 0.38; 'returned': 0.38; 'ways': 0.38; "it's": 0.39; 'case': 0.39; 'subject:: ': 0.39; 'might': 0.39; 'to:addr:python.org': 0.39; 'data': 0.40; 'more': 0.60; 'your': 0.61; 'from:addr:mail': 0.64; 'tag': 0.64; 'subject:. ': 0.65; 'reviews': 0.65; 'subject:Get': 0.71; 'mind:': 0.84 Date: Mon, 14 Nov 2011 10:42:50 +0000 From: Tim Golden User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary] References: <8f5215a8-d08f-4355-a5a2-77fcaa32c92d@j10g2000vbe.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321267380 news.xs4all.nl 6895 [2001:888:2000:d::a6]:53186 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15663 On 14/11/2011 10:05, Matej Cepl wrote: > Dne 11.11.2011 14:31, macm napsal(a): >> def Dicty( dict[k1][k2] ): > > When looking at this I returned to the question which currently rolls in > my mind: > > What's difference/advantage-disadvantage betweeng doing multi-level > dicts/arrays like this and using tuple as a key? I.e., is it more > Pythonic to have > > dict[k1,k2] > > instead? For me, it would depend on what the data meant. To give an obvious example: if you were storing things which were based on coords, then clearly map[x, y] is more meaningful than map[x][y]. Conversely, if your dictionary structure was, say, a set of preferences for users, then prefs[username][prefname] is probably a more useful model. Sometimes it's not so clear, in which case one person might opt for one approach while another opted for another while modelling the same data concepts. If, for example, you were modelling a set of book reviews where each review might have one or more genres (which you could display as a tag-cloud, say) then you could consider the model to be a sort of book-genre tag cloud: book_genres[title, genre] or a list of books in each genre: genres[genre][title] or a list of genres for each book: books[title][genre] or even multiple ways if that made it easier to use in one situation or another. Stating-the-obvious-ly yours, TJG