Re: unpacking first few items of iterable
On 12/13/2012 03:09 PM, Daniel Fetchinson wrote:
>>> Hi folks, I swear I used to know this but can't find it anywhere:
>>> What's the standard idiom for unpacking the first few items of an
>>> iterable whose total length is unknown?
>>> Something like
>>> a, b, c, _ = myiterable
>>> where _ could eat up a variable number of items, in case I'm only
>>> interested in the first 3 items?
>> If you're using python3, you can simply do:
>> a, b, c, *rest = myiterable
> Thanks, sounds great, how about python2?
If you know the sequence has at least n items, you
can do a, b, c = seq[:3]
Lark's Tongue Guide to Python: http://lightbird.net/larks/
|All times are GMT. The time now is 05:33 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.