list vs tuple
Aahz Maruch
aahz at panix.com
Wed Mar 28 14:35:09 EST 2001
In article <buqw6.1999$sk3.675030 at newsb.telia.net>,
Fredrik Lundh <fredrik at effbot.org> wrote:
>Mark Pilgrim wrote
>>
>> It was my understanding that only tuples containing immutable objects
>> could be used as dictionary keys. For instance, (1,2,3) can be, and
>> ("a","b","c") can be, but ([1,2,3], ["a","b","c"]) can not, because
>> the underlying objects could mutate and cause problems. (Wow, that
>> sounds like a bad sci-fi movie.) Is this true?
>
>no python interpreter within reach today?
>
>>>> d = {}
>>>> d[(1, 2, 3)] = 1
>>>> d[("a", "b", "c")] = 2
>>>> d[([1, 2, 3], ["a", "b", "c"])] = 3
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
>TypeError: unhashable type
Sure, but someone could create a class with __hash__ and do some weird
stuff that way. Not Recommended.
--
--- Aahz <*> (Copyright 2001 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het Pythonista http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
"Boost the stock market -- fire someone"
More information about the Python-list
mailing list