Is there a value in using map() vs for?

前端 未结 8 2729
误落风尘
误落风尘 2021-02-20 17:03

Does map() iterate through the list like \"for\" would? Is there a value in using map vs for?

If so, right now my code looks like this:

for item in item         


        
8条回答
  •  悲哀的现实
    2021-02-20 17:45

    Map can sometimes be faster for built-in functions than manually coding a for loop. Try timing map(str, range(1000000)) vs. a similar for loop.

提交回复
热议问题