Collections of non-arbitrary objects ?
walterbyrd
walterbyrd at iname.com
Thu Jun 28 12:01:37 EDT 2007
>
> Did you try to sort a tuple ?
>
> >>> (1, "aaa").sort()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AttributeError: 'tuple' object has no attribute 'sort'
I can do this:
>>> x = (3,2,1)
>>> x = tuple(sorted(list(x)))
Which, although senseless, effectively sorts the x tuple. But, you are
right, I am not really sorting the tuple, I'm sorting a list, which
has been made from the tuple, then changing it back to a tuple.
Actually, I can even do it in one line:
x = tuple(sorted(list((3,2,1))))
More information about the Python-list
mailing list