LISTS: Extract every other element
Adrian Eyre
a.eyre at optichrome.com
Fri Dec 17 07:37:21 EST 1999
> and build a list with every other element:
>
> [ 1,3,5,7,... ]
No idea how efficient these are:
>>> l = ['a', 'b', 'c', 'd']
>>> map(lambda x: l[x], range(0, len(l), 2))
['a', 'c']
or
>>> map(lambda x: l[x*2], range(len(l)/2))
['a', 'c']
--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233 Fax: +44 1483 760 644
http://www.optichrome.com
--------------------------------------------
More information about the Python-list
mailing list