Is there any nice way to unpack a list of unknown size??

Tim Chase python.list at
Sun Sep 14 21:16:04 CEST 2008

>> I want to do something like below:
>> 1. first, second, third, *rest = foo
> Python 3.0 has exactly this feature.  No current Python 2.x version has it.

I asked something similar[1] on c.l.p a while back and Diez 
Roggisch gave this nice workaround/hack[2]

It's a bit ugly in the implementation (sniffing the stack), but 
elegant in the use, doing exactly what I needed.

It doesn't accommodate the "rest" portion that you reference, but 
allows for arbitrary unpacking into a fixed-length tuple.




More information about the Python-list mailing list