Thoughts about Python
sross at connectmail.carleton.ca
Tue Feb 24 23:20:30 CET 2004
----- Original Message -----
From: "Duncan Booth" <me at privacy.net>
> > *** Problem: tuples are not necessary
> > Throw them away in the long run - for now make them depracted. It is
> > hard to argue in favour of tuples. There might to 2 reason:
> > 1. It is MUCH faster than a list
> > 2. We can't live without an immutable list
> Forget the speed and memory difference. The main argument for tuples as a
> separate type are to use as dictionary keys. How do you propose to handle
> dictionary keys without tuples?
Well, you _could_ (you won't, but you could ;) take some ideas from Ruby:
obj.freeze -> obj
Prevents further modifications to obj. A TypeError will be raised if
modification is attempted. There is no way to unfreeze a frozen object. See
also Object#frozen? .
I would think that myList.freeze() should allow myList to be used as a
dictionary key. Of course, now you'd have to freeze your lists before using
them in a dictionary ... I don't know why I bother ...
More information about the Python-list