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


Groups > comp.lang.python > #82123

Re: Nested dictionaries from a list ?

Date 2014-12-08 08:35 -0500
From Dave Angel <davea@davea.name>
Subject Re: Nested dictionaries from a list ?
References <72066852-b4a1-4820-b52a-be56f68a0d7b@googlegroups.com> <mailman.16678.1417971703.18130.python-list@python.org> <m62p8f$fn7$3@dont-email.me>
Newsgroups comp.lang.python
Message-ID <mailman.16722.1418045741.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/07/2014 06:52 PM, Denis McMahon wrote:
> On Sun, 07 Dec 2014 12:01:26 -0500, Dave Angel wrote:
>
>> On 12/07/2014 11:18 AM, Wacky wrote:
>
>>> I've a list of users ....
>
>> I haven't run this through the Python, so please forgive any typos.
>
>> users = [ ....
>> mess = { ....
>
> users is redundant, as it's mess.keys()
>
> maintaining a separate list of users and having the users as the keys in
> mess suggests redundancy, and the potential for errors if the two data
> items get out of synch. Better imo to just have the data in one place.
>

Unless there's an order that wants to be retained.  But I would change 
the list into a list of user objects, rather than of strings.  And I'd 
know that eventually it would be a sparse list (as users come and go, 
and you don't want to reuse the indices).  So it would be another 
dictionary mapping userid and User instance.

-- 
DaveA

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


Thread

Nested dictionaries from a list ? Wacky <waqar.hafiz@gmail.com> - 2014-12-07 08:18 -0800
  Re: Nested dictionaries from a list ? Dave Angel <davea@davea.name> - 2014-12-07 12:01 -0500
    Re: Nested dictionaries from a list ? Denis McMahon <denismfmcmahon@gmail.com> - 2014-12-07 23:52 +0000
      Re: Nested dictionaries from a list ? Dave Angel <davea@davea.name> - 2014-12-08 08:35 -0500
  Re: Nested dictionaries from a list ? Denis McMahon <denismfmcmahon@gmail.com> - 2014-12-07 23:49 +0000

csiph-web