Death to tuples!

skip at pobox.com skip at pobox.com
Mon Nov 28 16:48:47 EST 2005


    >>> For those of us not following this thread closely, can you identify
    >>> cases where tuples are mutable, not hashable or can't be used as
    >>> dictionary keys?  I've never encountered any such cases.
    >> 
    >> t = ([1,2], [3,4])

    ...

    >>>> t = ([1,2], [3,4])
    >>>> t[0] += [5]
    aahz> Traceback (most recent call last):
    aahz>   File "<stdin>", line 1, in ?
    aahz> TypeError: object doesn't support item assignment
    >>>> t
    aahz> ([1, 2, 5], [3, 4])

    aahz> (I'm pretty sure Skip has seen this before, but I figure it's a
    aahz> good reminder.)

Actually, no, I hadn't.  I don't use tuples that way.  It's rare when I have
a tuple whose elements are not all floats, strings or ints, and I never put
mutable containers in them.

Skip



More information about the Python-list mailing list