Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15663

Re: Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary]

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 <mail@timgolden.me.uk>
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 <mail@timgolden.me.uk>
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> <j9qp2t$1lnr$1@ns.felk.cvut.cz>
In-Reply-To <j9qp2t$1lnr$1@ns.felk.cvut.cz>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2694.1321267380.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 05:31 -0800
  Re: Get keys from a dicionary Jon Clements <joncle@googlemail.com> - 2011-11-11 08:09 -0800
    Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:33 -0800
      Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:38 -0800
      Re: Get keys from a dicionary Dave Angel <d@davea.name> - 2011-11-11 11:47 -0500
      Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 17:28 +0000
  Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 16:25 +0000
    Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:36 -0800
  Re: Get keys from a dicionary Gelonida N <gelonida@gmail.com> - 2011-11-11 18:29 +0100
  Re: Get keys from a dicionary Gelonida N <gelonida@gmail.com> - 2011-11-11 18:45 +0100
    Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 17:51 +0000
  Re: Get keys from a dicionary alex23 <wuwei23@gmail.com> - 2011-11-13 21:42 -0800
  Re: Get keys from a dicionary alex23 <wuwei23@gmail.com> - 2011-11-13 21:44 -0800
  Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary] Matej Cepl <mcepl@redhat.com> - 2011-11-14 11:05 +0100
    Re: Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary] Tim Golden <mail@timgolden.me.uk> - 2011-11-14 10:42 +0000
    Re: Multilevel dicts/arrays v. tuples as keys? Peter Otten <__peter__@web.de> - 2011-11-14 11:47 +0100
      Re: Multilevel dicts/arrays v. tuples as keys? alex23 <wuwei23@gmail.com> - 2011-11-14 19:07 -0800

csiph-web