What is the output of the following Python code:
test = [0, 1, 2]
def increment(x):
return X+2
print(list(map(test, increment)))
Answers
Answered by
1
It will throw an error as the code is incorrect.
Corrected code
test = [0, 1, 2]
def increment(x):
return X+2
print(list(map(increment, test)))
It will output [2, 3, 4] as map function will apply the increment function to each item in test list.
You don't need a function for something this trivial, you can make it inline like this.
test = [0, 1, 2]
print(list(map(lambda x: x + 2, test)))
Similar questions