I want to be able to add a number to a number in list. I do not want to add numbers TO a list. I want to add to numbers IN a list. There is just 2 numbers in the list and I want to add to each of those. I want to add the same number to each, 1.
When I tried making a list and just saying list + 1 I got a Type error. Here is what I tried:
my_list = [2 , 3 ]
my_list1 = my_list + 1
print(my_list)
>Solution :
my_list = [2,3]
#Solution 1
my_list = [item +1 for item in my_list]
#Solution 2
for i in range(len(my_list)):
my_list[i] += 1
#Solution 3
my_list = list(map(lambda x: x + 1, my_list))
#Solution 4
import numpy as np
my_list = np.array(my_list) + 1
my_list = my_list.tolist()