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