Do a map on list : map « Buildin Function « Python






Do a map on list

Do a map on list

counters = [1, 2, 3, 4]

updated = []
for x in counters:
     updated.append(x + 10)              # add 10 to each item

print updated

def inc(x): return x + 10               # function to be run

print map(inc, counters)                      # collect results


print map((lambda x: x + 3), counters)        # function expression

           
       








Related examples in the same category

1.Map: lambda function insideMap: lambda function inside
2.A sentence is split up into a list of wordsA sentence is split up into a list of words
3.Functional Programming Tools: mapFunctional Programming Tools: map
4.Functional Programming Tools: map: More than one sequence may be passedFunctional Programming Tools: map: More than one sequence may be passed
5.Use mapUse map