A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-February/002019.html below:

[Python-Dev] re: syntax - "Aren't tuples redundant?"

[Python-Dev] re: syntax - "Aren't tuples redundant?"Gordon McMillan gmcm@hypernet.com
Thu, 3 Feb 2000 15:42:25 -0500
[Greg Wilson]

> 4. "Aren't tuples redundant?"
> 
> I explained that the const-ness of tuples was needed so that they
> could be used as dictionary keys.  The guy with Perl in his background
> immediately asked if that's reliable --- a tuple can contain a list,
> which can be mutated. You've all heard this one more times than I
> have...

I guess you didn't try it:

>>> t = ([0,1],2)
>>> d = {}
>>> d[t] = "hooey"
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: unhashable type
>>>

To pass the hash test, it needs to have immutable contents 
as well.

To my mind, the "can act as dictionary key" argument is a red 
herring. Tuples and lists may technically be almost the same 
thing, but I find I hardly ever need to ponder whether I should 
use a tuple or a list. Tuples are structures and lists are 
containers. Yes, you can use a container as a structure. You 
can also use a bucket as a spoon.

or-stick-your-head-straight-into-the-trough-ly y'rs

- Gordon



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4