unpacking first few items of iterable
Ian Kelly
ian.g.kelly at gmail.com
Thu Dec 13 15:50:08 EST 2012
On Thu, Dec 13, 2012 at 1:39 PM, Daniel Fetchinson
<fetchinson at googlemail.com> wrote:
>> If you know the sequence has at least n items, you
>> can do a, b, c = seq[:3]
>
> Yeah, that's probably the simplest, without all the fancy stuff :)
That only works for sequences, though. Not all iterables are
sequences. The islice version proposed by MRAB is more generally
applicable.
More information about the Python-list
mailing list