A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-October/057061.html below:

[Python-Dev] Extending tuple unpacking

[Python-Dev] Extending tuple unpackingGustavo Niemeyer gustavo at niemeyer.net
Fri Oct 7 19:56:10 CEST 2005
> Someone should really write up a PEP -- this was just discussed a week
> or two ago.

Heh.. I should follow the list more closely.

> I personally think this is adequately handled by writing:
> 
>   (first, second), rest = something[:2], something[2:]

That's an alternative indeed. But the the proposed way does look better:

  for item in iterator:
      (first, second), rest = item[2:], item[:2]
      ...

vs.

  for first, second, *rest in iterator:
     ...

> I believe that this wish is an example of "hypergeneralization" -- an
> incorrect generalization based on a misunderstanding of the underlying
> principle.

Thanks for trying so hard to say in a nice way that this is not
a good idea. :-)

> Argument lists are not tuples [*] and features of argument lists
> should not be confused with features of tuple unpackings.

Do you agree that the concepts are related?

For instance:

  >>> def f(first, second, *rest):
  ...   print first, second, rest
  ...
  >>> f(1,2,3,4)
  1 2 (3, 4)

  >>> first, second, *rest = (1,2,3,4)
  >>> print first, second, rest
  1 2 (3, 4)

> [*] Proof: f(1) is equivalent to f(1,) even though (1) is an int but
> (1,) is a tuple.

"Extended *tuple* unpacking" was a wrong subject indeed. This is
general unpacking, since it's supposed to work with any sequence.

-- 
Gustavo Niemeyer
http://niemeyer.net
More information about the Python-Dev mailing list

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