map用来对一个列表里的元素分别调用同一函数进行处理,然后返回一个新的列表
#范例1: >>> print map(abs, [-5,7,-12] ) [5, 7, 12] #范例2: >>> print [abs(i) for i in [-5,7,-12]] [5, 7, 12] #范例3: >>> def myfunction(value): ... return value*10+1 ... >>> print map(myfunction, [1,2,3,4] ) [11, 21, 31, 41] >>> #范例4: >>> print map(max, [4,5,6], [1,2,9] ) [4, 5, 9] #范例5: >>> [ max(4,1), max(5,2), max(6,9) ] [4, 5, 9]
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8442.html