List mapping?
Hakan Nilsson
hakan at netg.se
Thu Apr 13 11:50:19 EDT 2000
On Thu, 13 Apr 2000, Robert Cragie wrote:
> > Try this:
> > mylist = ['/a','1','/b','2','/c','3']
> > map(lambda x: reduce(lambda a, b: (a,b), mylist[x:x+2]), range(0,
> > len(mylist), 2))
>
> Sorry, forgot to assign...
>
> mylist = ['/a','1','/b','2','/c','3']
> tuplist = map(lambda x: reduce(lambda a, b: (a,b), mylist[x:x+2]), range(0,
> len(mylist), 2))
>
> Robert Cragie
>
>
Howcome you use reduce at all?
Works fine with just doing
tuplist = map(lambda x: (mylist[x], mylist[x+1]), range(0, len(mylist),
2))
Reduce has many uses, but I can't see why this should be one of them ;o)
(as mentioned, getopts would be even better though;)
/H
Håkan Nilsson NetGuide Scandinavia
hakan at netg.se 031-50 79 40
More information about the Python-list
mailing list