Re: Dictionaries of Lists

2005-03-07 Thread Steven Bethard
Tony Meyer wrote: [a for a in list] (or a[:]) makes a copy of a list. or list(a) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries of Lists

2005-03-07 Thread Terry Hancock
On Monday 07 March 2005 11:09 pm, gf gf wrote: > I'd like to associate certain lists with keywords, and > retrieve them. But this is not possible as lists are > not hashable. > > What is the best workaround? I don't mind making my > lists immutable. Is there a way to tupelize them? > I tried my

RE: Dictionaries of Lists

2005-03-07 Thread Tony Meyer
> I'd like to associate certain lists with keywords, and > retrieve them. But this is not possible as lists are > not hashable. A dictionary's values don't have to be hashable, so if the keywords are the keys in the dictionary, this would work. >>> d = {} >>> d['key1'] = [1,2,3] >>> d['key2'] =

Re: Dictionaries of Lists

2005-03-07 Thread Robert Kern
gf gf wrote: I'd like to associate certain lists with keywords, and retrieve them. But this is not possible as lists are not hashable. Do you want mydict[mylist] = mykey or mydict[mykey] = mylist ? The former is not possible with lists for the reason you noted. The latter, however, works just

Re: Dictionaries of Lists

2005-03-07 Thread Erik Max Francis
gf gf wrote: I'd like to associate certain lists with keywords, and retrieve them. But this is not possible as lists are not hashable. You can convert them to tuples with the `tuple' function: aDictionary[tuple(aList)] = aKeyword > What is the best workaround? I don't mind making my > lis