I have a list:
my_list = [1, 2, 3, 4, 5]
How can I multiply each element in my_list
by 5? The output should be:
from functools import partial as p
from operator import mul
map(p(mul,5),my_list)
is one way you could do it ... your teacher probably knows a much less complicated way that was probably covered in class
Best way is to use list comprehension:
def map_to_list(my_list, n):
# multiply every value in my_list by n
# Use list comprehension!
my_new_list = [i * n for i in my_list]
return my_new_list
# To test:
print(map_to_list([1,2,3], -1))
Returns: [-1, -2, -3]