Death to tuples!

skip at skip at
Mon Nov 28 22:48:47 CET 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.


More information about the Python-list mailing list