Monday, July 07, 2008

Python note: functional programming saves code when dealing with lists

Another note on using functional programming. It makes code with lists shorter and clearer sometimes.

For example, there is a list l. We want to add one to each element:

l = map(lambda x: x+1, l)

1 comment:

Xi.Cheng said...

how about?
newl = [ x+1 for x in l ]

I searched 'merging files python' and found your post! Dude! 20090405