Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

map in python

'''
Map:
A standard function that accepts at least "two-arguments",
a function and an "iterable"

Iterable - something that can be iterated over (list, dictionary,
strings, sets, tuples)

runs the Lambda for each value in the iterable and 
returns a map object which can be converted into another data structure

Keyword:
map(function/lambda func., variable)
'''
# Example:
nums = [1,2,3,4]
power = map(math.pow(2), nums)
print(list(power)) # 1, 4, 9, 16
powerLamb = map(lambda x: x**2, nums) # 1, 4, 9, 16
Source by book.pythontips.com #
 
PREVIOUS NEXT
Tagged: #map #python
ADD COMMENT
Topic
Name
4+6 =