Re: [Tutor] Group sequence pairwise

2007-02-27 Thread Christopher Arndt
Justin Ezequiel schrieb: a = list('asdfg') map(None, a[::2], a[1::2]) > [('a', 's'), ('d', 'f'), ('g', None)] a = list('asdfgh') map(None, a[::2], a[1::2]) > [('a', 's'), ('d', 'f'), ('g', 'h')] That's clever! Thanks! Chris ___ Tutor

Re: [Tutor] Group sequence pairwise

2007-02-26 Thread Justin Ezequiel
>>> a = list('asdfg') >>> map(None, a[::2], a[1::2]) [('a', 's'), ('d', 'f'), ('g', None)] >>> a = list('asdfgh') >>> map(None, a[::2], a[1::2]) [('a', 's'), ('d', 'f'), ('g', 'h')] >>> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailma

Re: [Tutor] Group sequence pairwise

2007-02-25 Thread Christopher Arndt
David Perlman schrieb: > I found this by "using Google". You should be able to make a simple > modification (I can think of a couple of ways to do it) to have it > pad the end with "None". It is 100% iterator input and output. > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/30327

Re: [Tutor] Group sequence pairwise

2007-02-25 Thread David Perlman
I found this by "using Google". You should be able to make a simple modification (I can think of a couple of ways to do it) to have it pad the end with "None". It is 100% iterator input and output. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279 On Feb 25, 2007, at 7:06 AM, C

Re: [Tutor] Group sequence pairwise

2007-02-25 Thread Christopher Arndt
Luke Paireepinart schrieb: > Christopher Arndt wrote: >> I have tried to find a solution, using itertools, but I'm not very >> experienced in functional stuff, so I got confused. > Do you mean you're not experienced in using functions or do you mean > you're inexperienced at functional programmin

Re: [Tutor] Group sequence pairwise

2007-02-25 Thread Luke Paireepinart
Christopher Arndt wrote: > Given a sequence, how can I group it pairwise, so that I get > > [(s0, s1), (s2, s3), ... , (sn-1, sn)] > > or, if len(s)%2 != 0 > > [(s0, s1), (s2, s3), ... , (sn, None)] > > > I have tried to find a solution, using itertools, but I'm not very > experienced in functional