Usage of map in Python

From , 3 Years ago, written in Python, viewed 53 times.
URL https://pastebin.vip/view/79e3eb7e
  1. #范例1:
  2. >>> print map(abs, [-5,7,-12] )
  3. [5, 7, 12]
  4.  
  5. #范例2:
  6. >>> print [abs(i) for i in [-5,7,-12]]
  7. [5, 7, 12]
  8.  
  9. #范例3:
  10. >>> def myfunction(value):
  11. ...     return value*10+1
  12. ...
  13. >>> print map(myfunction, [1,2,3,4] )
  14. [11, 21, 31, 41]
  15. >>>
  16.  
  17. #范例4:
  18. >>> print map(max, [4,5,6], [1,2,9] )
  19. [4, 5, 9]
  20.  
  21. #范例5:
  22. >>> [ max(4,1), max(5,2), max(6,9) ]
  23. [4, 5, 9]
  24. #//python/237

Reply to "Usage of map in Python"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website