Python Various Ways of Writing Loops
- List Comprehension
[2*x+3 for x in list]
A function can also be defined on the fly.
map(lambda x: function of x, list)
map(lambda x,y:x+y, xlist, ylist)
zip is useful in a map of multivariable function.
As given in the reference link, one good example is
mapand list comprehension
[map(lambda x: x+3, list) for list in shape2by2list]
Published: by Lei Ma;
Table of Contents