Re: grouping a flat list of number by range

2006-06-04 Thread Steven Bethard
[EMAIL PROTECTED] wrote: >> ... _, first_n = group[0] > > what is the meaning of the underscore "_" ? is it a special var ? or > should it be readed as a way of unpacking a tuple in a non useful var ? > like > > lost, first_n = group[0] Yep, it's just another name. "lost" would have wo

Re: grouping a flat list of number by range

2006-06-04 Thread K.S.Sreeram
Yup! '_' is just used as a dummy. Its a pretty common idiom. There's nothing special about that variable. [EMAIL PROTECTED] wrote: > Hello > >> ... _, first_n = group[0] > > what is the meaning of the underscore "_" ? is it a special var ? or > should it be readed as a way of unpacking a

Re: grouping a flat list of number by range

2006-06-04 Thread joh12005
Hello > ... _, first_n = group[0] what is the meaning of the underscore "_" ? is it a special var ? or should it be readed as a way of unpacking a tuple in a non useful var ? like lost, first_n = group[0] best regards. -- http://mail.python.org/mailman/listinfo/python-list

Re: grouping a flat list of number by range

2006-06-03 Thread Steven Bethard
Gerard Flanagan wrote: > [EMAIL PROTECTED] wrote: >> hello, >> >> i'm looking for a way to have a list of number grouped by consecutive >> interval, after a search, for example : >> >> [3, 6, 7, 8, 12, 13, 15] >> >> => >> >> [[3, 4], [6,9], [12, 14], [15, 16]] >> >> (6, not following 3, so 3 => [3:

Re: grouping a flat list of number by range

2006-06-03 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote: > hello, > > i'm looking for a way to have a list of number grouped by consecutive > interval, after a search, for example : > > [3, 6, 7, 8, 12, 13, 15] > > => > > [[3, 4], [6,9], [12, 14], [15, 16]] > > (6, not following 3, so 3 => [3:4] ; 7, 8 following 6 so 6, 7, 8 => >

Re: grouping a flat list of number by range

2006-06-03 Thread joh12005
thanks to all ! my version was far less clever/long thant the one you posted, i'm going to examine all these with much interest, and learn... best regards. -- http://mail.python.org/mailman/listinfo/python-list

Re: grouping a flat list of number by range

2006-06-02 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > i'm looking for a way to have a list of number grouped by consecutive > interval, after a search, for example : > > [3, 6, 7, 8, 12, 13, 15] > > => > > [[3, 4], [6,9], [12, 14], [15, 16]] Know your itertools. From the examples section[1]: """ # Find runs of consecut

Re: grouping a flat list of number by range

2006-06-02 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Paddy <[EMAIL PROTECTED]> wrote: > >John Machin wrote: >> On 2/06/2006 8:36 AM, Paddy wrote: > >> >> Oh the siren call of every new feature in the language! >> enumerate() just to get a first-time test, and then botch it?? >> >> Read the following; the replacement ve

Re: grouping a flat list of number by range

2006-06-02 Thread Paddy
John Machin wrote: > On 2/06/2006 8:36 AM, Paddy wrote: > > Oh the siren call of every new feature in the language! > enumerate() just to get a first-time test, and then botch it?? > > Read the following; the replacement version uses a simple old-fashioned > inelegant flag, works with an empty se

Re: grouping a flat list of number by range

2006-06-01 Thread Paddy
Jim Segrave wrote: > In article <[EMAIL PROTECTED]>, > Paddy <[EMAIL PROTECTED]> wrote: > > > >What I ran was more like the version below, but i did a quick > >separation of the line that has the ';' in it and goofed. > > > def interv2(inlist): > >... for i,val in enumerate(inlist): > >...

Re: grouping a flat list of number by range

2006-06-01 Thread Gerard Flanagan
Gerard Flanagan wrote: > [EMAIL PROTECTED] wrote: > > hello, > > > > i'm looking for a way to have a list of number grouped by consecutive > > interval, after a search, for example : > > > > [3, 6, 7, 8, 12, 13, 15] > > > > => > > > > [[3, 4], [6,9], [12, 14], [15, 16]] > > > > (6, not following 3

Re: grouping a flat list of number by range

2006-06-01 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote: > hello, > > i'm looking for a way to have a list of number grouped by consecutive > interval, after a search, for example : > > [3, 6, 7, 8, 12, 13, 15] > > => > > [[3, 4], [6,9], [12, 14], [15, 16]] > > (6, not following 3, so 3 => [3:4] ; 7, 8 following 6 so 6, 7, 8 => >

Re: grouping a flat list of number by range

2006-06-01 Thread John Machin
On 2/06/2006 8:36 AM, Paddy wrote: > [EMAIL PROTECTED] wrote: >> hello, >> >> i'm looking for a way to have a list of number grouped by consecutive >> interval, after a search, for example : >> >> [3, 6, 7, 8, 12, 13, 15] >> >> => >> >> [[3, 4], [6,9], [12, 14], [15, 16]] >> >> (6, not following 3,

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Paddy <[EMAIL PROTECTED]> wrote: > >What I ran was more like the version below, but i did a quick >separation of the line that has the ';' in it and goofed. > def interv2(inlist): >...for i,val in enumerate(inlist): >...if i==0: >...

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Paddy <[EMAIL PROTECTED]> wrote: >I did a little re-arranging of the generator version: > >def interv3(inlist): >tmp = inlist[0] >valinc = tmp+1 >for val in inlist[1:]: >if val != valinc: >yield [tmp, valinc]; >tmp = val >

Re: grouping a flat list of number by range

2006-06-01 Thread Paddy
Jim Segrave wrote: > In article <[EMAIL PROTECTED]>, > Paddy <[EMAIL PROTECTED]> wrote: > >=== interv2 === > def interv2(inlist): > >... for i,val in enumerate(inlist): > >... if i==0: > >... tmp = val > >... elif val != valinc: > >... yiel

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Paddy <[EMAIL PROTECTED]> wrote: >=== interv2 === def interv2(inlist): >...for i,val in enumerate(inlist): >...if i==0: >...tmp = val >...elif val != valinc: >...yield [tmp, valinc] >...

Re: grouping a flat list of number by range

2006-06-01 Thread Paddy
I did a little re-arranging of the generator version: def interv3(inlist): tmp = inlist[0] valinc = tmp+1 for val in inlist[1:]: if val != valinc: yield [tmp, valinc]; tmp = val valinc = val+1 yield [tmp, valinc] -- http://mail.python.org/m

Re: grouping a flat list of number by range

2006-06-01 Thread Paddy
[EMAIL PROTECTED] wrote: > hello, > > i'm looking for a way to have a list of number grouped by consecutive > interval, after a search, for example : > > [3, 6, 7, 8, 12, 13, 15] > > => > > [[3, 4], [6,9], [12, 14], [15, 16]] > > (6, not following 3, so 3 => [3:4] ; 7, 8 following 6 so 6, 7, 8 => >

Re: grouping a flat list of number by range

2006-06-01 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: > i'm looking for a way to have a list of number grouped by consecutive > interval, after a search, for example : > > [3, 6, 7, 8, 12, 13, 15] > > => > > [[3, 4], [6,9], [12, 14], [15, 16]] > > (6, not following 3, so 3 => [3:4] ; 7, 8 following 6 so 6, 7, 8 => > [6:9], and

Re: grouping a flat list of number by range

2006-06-01 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: >hello, > >i'm looking for a way to have a list of number grouped by consecutive >interval, after a search, for example : > >[3, 6, 7, 8, 12, 13, 15] > >=> > >[[3, 4], [6,9], [12, 14], [15, 16]] > >(6, not following 3, so 3 => [3:4] ; 7, 8

Re: grouping a flat list of number by range

2006-06-01 Thread Peter Otten
[EMAIL PROTECTED] wrote: > i'm looking for a way to have a list of number grouped by consecutive > interval, after a search, for example : > > [3, 6, 7, 8, 12, 13, 15] > > => > > [[3, 4], [6,9], [12, 14], [15, 16]] > > (6, not following 3, so 3 => [3:4] ; 7, 8 following 6 so 6, 7, 8 => > [6:9]

grouping a flat list of number by range

2006-06-01 Thread joh12005
hello, i'm looking for a way to have a list of number grouped by consecutive interval, after a search, for example : [3, 6, 7, 8, 12, 13, 15] => [[3, 4], [6,9], [12, 14], [15, 16]] (6, not following 3, so 3 => [3:4] ; 7, 8 following 6 so 6, 7, 8 => [6:9], and so on) i was able to to it withou