tuples are useless???

James Stroud jstroud at mbi.ucla.edu
Mon Apr 9 04:26:37 CEST 2007

Bart Willems wrote:
> James Stroud wrote:
>> ... It boils down to the fact that tuples are useless as a result 
>> unless you know you really need them--and you never really NEED them.
> Could you clarify that for me? I use tuples *a lot* and I really *NEED* 
> them - I'm building a lot of multi-tier reports where detail-level data 
> is pulled out of a dictionary based on a composed key. It is impossible 
> to build those dictionaries *without* using tuples.

"Impossible" is a strong word, as is "need" (especially when in all caps).

py> import md5
py> class HashedList(list):
...   def __hash__(self):
...     h = md5.new()
...     for item in self:
...       h.update(str(hash(item)))
...     return int(h.hexdigest(), 16)
py> hl = HashedList('bob', 'carol', 'ted')
py> {hl:3}
{['bob', 'carol', 'ted']: 3}

Impossible? I wouldn't even say that this was all that difficult.


More information about the Python-list mailing list