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? > >

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 i

Re: unpacking first few items of iterable

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

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 n

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

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 n

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 onl

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 numb

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" 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

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