Thoughts about Python

Marco Aschwanden PPNTWIMBXFFC at
Wed Feb 25 10:23:37 CET 2004

cookedm+news at (David M. Cooke) wrote in message news:<qnk4qtgt7j9.fsf at>...
> At some point, PPNTWIMBXFFC at (Marco Aschwanden) wrote:
> >> 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?
> >
> > Maybe I don't get the point here: Why do dictionaries need tuples to
> > work? I know that tuples can be used as keys... but how many times do
> > you need tuples as dictionary keys (it would be simple to turn a list
> > into an immutable string if really needed ("::".join(["a","b"]).
> Simple, yes. Practicable, no. Wrong, certainly. For instance, I have a
> lot of use cases where I use tuples of numbers -- (3, 4, 20.0101), eg.
> It'd be a *hack* to convert that into a string, and the representation
> would not be unique. This ain't Perl.

>>> tup = (3, 4, 20.0101)
>>> stringified = str(tup)
>>> stringified
'(3, 4, 20.010100000000001)'  # 8o)
What is not unique about this string?
Okay, I can think of cases where this approach is problematic -
foremost when sorting is involved.
It is also a bit complicated to retrieve the values from the string
(it has to be "split"ted or "eval"ed back to a tuple or list).
If this pattern would be seldom used... but it seems, that everybody
except me uses this dicts as keys.

And yes, luckily this is not Perl.


More information about the Python-list mailing list