Map Function in Python
Level 392 keystrokes
This doubles each number using map(), printing [2, 4, 6]. map() applies a function to every element in an iterable.
Python code
# Define a function that takes a number and returns its double1def double(x): # Multiply x by 2 and return the result2 return x * 23 # Create a list of numbers4nums = [1, 2, 3]# map() applies the double function to each element# list() converts the map object to a list5result = list(map(double, nums))# Print the transformed list6print(result)Output
[2, 4, 6]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
(× 4)× 4,× 3=× 2:× 1[× 1]× 1*× 1