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
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
> 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'] =
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
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