Map isn't pythonic, use list instead.
map(func, iterable)
func : It is a function to which map passes each element of given iterable.
iter : It is a list which is to be mapped( list of parameters to be passed to func).
lets say:
>>> func add(a):
>>> return a+5;
>>> print add(2) // 2 as parameter, it will return 2+5=77
//lets give a list of parameters instead of only 1 param
>>> myList = (2,6,7,1)
//first lets do the same with for loop.
>>> for i in number:
... print add(i);...
96
// lets do the same with list.
func add(a):
returnn a+5;
myList = (2,6,7,1);
// all items of list will be the parameter for the function add().
>>> print map(add, myList)
[6, 10, 11, 5]
No comments:
Post a Comment