Python 3.0 - is this true?
"Martin v. Löwis"
martin at v.loewis.de
Mon Nov 10 04:10:19 EST 2008
Roy Smith wrote:
> Your
> choice of containers is not based on any theoretical arguments of what each
> type was intended to represent, but the cold hard reality of what
> operations they support.
Right. What seems missing is a "frozen list" type - the list needs to be
frozen in order to be used as a dictionary key (or any other lookup
structure). Fortunately, as you say, tuples already fill that role, so
one could write
frozenlist = tuple
...
sequence = frozenlist(items)
d[sequence] = d.get(sequence,0)+1
to make it explicit that here, the tuple has a different role.
Regards,
Martin
More information about the Python-list
mailing list