Python - Map function vs list comprehension

Introduction

The map call is similar to the list comprehension expressions:

Demo

def inc(x): return x + 10                  # Function to be run 
#  w  w w.  j av a 2  s  .c  o  m
d=list(map(inc, [1, 2, 3, 4])) 
print( d )


d=[inc(x) for x in [1, 2, 3, 4]]        # Use () parens to generate items instead 
print( d )

Result

Related Topic