unpacking first few items of iterable

2012-12-13 Thread Daniel Fetchinson
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

Re: unpacking first few items of iterable

2012-12-13 Thread Demian Brecht
If you're using python3, you can simply do: a, b, c, *rest = myiterable Demian Brecht http://demianbrecht.github.com On 2012-12-13 11:37 AM, Daniel Fetchinson fetchin...@googlemail.com wrote: Hi folks, I swear I used to know this but can't find it anywhere: What's the standard idiom for

Re: unpacking first few items of iterable

2012-12-13 Thread MRAB
On 2012-12-13 19:37, 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

Re: unpacking first few items of iterable

2012-12-13 Thread Daniel Fetchinson
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

Re: unpacking first few items of iterable

2012-12-13 Thread Mitya Sirenef
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

Re: unpacking first few items of iterable

2012-12-13 Thread Daniel Fetchinson
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

Re: unpacking first few items of iterable

2012-12-13 Thread Mitya Sirenef
On 12/13/2012 03:39 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

Re: unpacking first few items of iterable

2012-12-13 Thread Ian Kelly
On Thu, Dec 13, 2012 at 1:39 PM, Daniel Fetchinson fetchin...@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

Re: unpacking first few items of iterable

2012-12-13 Thread Terry Reedy
On 12/13/2012 3:09 PM, MRAB wrote: On 2012-12-13 19:37, 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? An hinted by some of the answers, this

Re: unpacking first few items of iterable

2012-12-13 Thread Peter Otten
Terry Reedy wrote: On 12/13/2012 3:09 PM, MRAB wrote: On 2012-12-13 19:37, 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? An hinted by