Filling in a tuple from unknown size list

inhahe inhahe at gmail.com
Sun Nov 29 05:01:15 EST 2009


On Sun, Nov 29, 2009 at 4:42 AM, 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]
>
> not that that solves the None problem, though i don't have any feature
> suggestions that would address that.
>
>
Maybe instead of Python working this way:

>>> a, b = xrange(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack

it should work this way:

>>> a, b = xrange(10)
>>> print a, b
0 1

and then they could include something in itertools that automatically fills
extras with None, like Peter Otten's implementation but without having to
pass it a value for the number of assignments, i.e.:
a, b, c = itertools.ifill(list)
with None being the default fill value, but if we wanted 1 to be, we could
do
a, b, c = itertools.ifill(list, 1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091129/0382acaa/attachment-0001.html>


More information about the Python-list mailing list