Filling in a tuple from unknown size list

Ned Deily nad at acm.org
Sun Nov 29 19:12:56 CET 2009


In article 
<da776a8c0911290142o8ddce42n4825188bc5e23c50 at mail.gmail.com>,
 inhahe <inhahe at gmail.com> wrote:
> maybe that thing in python 3 that someone mentioned is the answer, but
> otherwise i always think Python should admit something like this:
> 
> a, b, c, *d = list
> 
> i.e. if list were [1,2,3,4,5], you'd get a=1, b=2, c=3, d=[4, 5]

Extended iterable unpacking (http://www.python.org/dev/peps/pep-3132/) 
is implemented in python 3.

$ python3
Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a, b, c, *d = [1,2,3,4,5]
>>> d
[4, 5]

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list