[Tutor] extracting numbers from a list
John Fouhy
john at fouhy.net
Tue Oct 17 03:20:23 CEST 2006
On 17/10/06, Asrarahmed Kadri <ajkadri at googlemail.com> wrote:
> My solution : (i have tested it)
As long as we're all taking turns, what about a functional approach:
>>> a = [10, 15, 18, 20, 25, 30, 40]
>>> def pairs(lst):
... return list.__add__([(lst[0], lst[1])], zip(map((1).__add__,
lst[1:]), lst[2:]))
...
>>> pairs(a)
[(10, 15), (16, 18), (19, 20), (21, 25), (26, 30), (31, 40)]
--
John.
More information about the Tutor
mailing list