Re: Multiple values for one key

2008-08-28 Thread Willi Richert
Hi, try defaultdict: In [1]: from collections import defaultdict In [2]: d=defaultdict(list) In [3]: d[1].append(7) In [4]: d[1].append(8) In [5]: d Out[5]: defaultdict(, {1: [7, 8]}) In [6]: d[1] Out[6]: [7, 8] Regards, wr Am Donnerstag 28 August 2008 19:02:55 schrieb Ron Brennan: > I hav

Re: Multiple values for one key

2008-08-28 Thread Chris Rebert
On Thu, Aug 28, 2008 at 10:02 AM, Ron Brennan <[EMAIL PROTECTED]> wrote: > I have another question. > > How would like to be able to add the contents on the values for one key. > > key['20001']:[978, 345] I'm assuming that by this you meant: assert the_dict['20001'] == [978, 345] > > How can I do

Re: Multiple values for one key

2008-08-28 Thread Ron Brennan
I have another question. How would like to be able to add the contents on the values for one key. key['20001']:[978, 345] How can I do this? Thanks, Ron On Thu, Aug 28, 2008 at 11:56 AM, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > norseman a écrit : > >> Terry Reedy wrote: >> >>> >>> >>

Re: Multiple values for one key

2008-08-28 Thread Tim Rowe
2008/8/28 Bruno Desthuilliers <[EMAIL PROTECTED]>: > You can either use 1/ a list of dicts, or 2/ a dict mapping keys to lists. > > 1/ > records = [ > {"name":"guy", "address":"unknown","zip":"0"}, > {"name":"girl", "address":"123 tiny street","zip":"12345"}, > {"name":"boy", "address":"

Re: Multiple values for one key

2008-08-28 Thread Bruno Desthuilliers
norseman a écrit : Terry Reedy wrote: Ron Brennan wrote: Hello, How would I create a dictionary that contains multiple values for one key. Make the value a collection object (set or list if you plan to add and delete). I'd also like the key to be able to have duplicate entries.

Re: Multiple values for one key

2008-08-28 Thread Maric Michaud
Le Thursday 28 August 2008 03:43:16 norseman, vous avez écrit : > Terry Reedy wrote: > > Ron Brennan wrote: > >> Hello, > >> > >> > >> How would I create a dictionary that contains multiple values for one > >> key. > > > > Make the value a collection object (set or list if you plan to add and > > d

Re: Multiple values for one key

2008-08-27 Thread norseman
Terry Reedy wrote: Ron Brennan wrote: Hello, How would I create a dictionary that contains multiple values for one key. Make the value a collection object (set or list if you plan to add and delete). I'd also like the key to be able to have duplicate entries. Dict keys must be ha

Re: Multiple values for one key

2008-08-27 Thread Maric Michaud
Le Thursday 28 August 2008 01:56:54 Terry Reedy, vous avez écrit : > >  I'd also like the key to be able to have duplicate entries. > > Dict keys must be hashable and unique. Let's admit they don't have to be unique (it's easy to implement all sort of data structures in pure python), but what wou

Re: Multiple values for one key

2008-08-27 Thread Terry Reedy
Ron Brennan wrote: Hello, How would I create a dictionary that contains multiple values for one key. Make the value a collection object (set or list if you plan to add and delete). I'd also like the key to be able to have duplicate entries. Dict keys must be hashable and unique.

Re: Multiple values for one key

2008-08-27 Thread Fredrik Lundh
Ron Brennan wrote: How would I create a dictionary that contains multiple values for one key. I'd also like the key to be able to have duplicate entries. look for the thread titled "python multimap". -- http://mail.python.org/mailman/listinfo/python-list