My Question is as follows:
- I want to loop through a list and assign the current iterated index value to a variable.
- In the same step I want to add this values into a second list in wich are already values.
- like this I want to add (+) every value in the list with every value of the same index in the second list via a loop
This could be an output like: l1 = [1, 2, 3] l2 = [4, 5, 6]
l3 = [5, 7, 9]
This is the code I have so far:
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
new_list = [44, 55, 66, 77, 88, 99, 11, 22, 33]
for x in new_list:
new_x = x
print(new_x)
my_new_numbers = [n + new_x for n in my_list]
print(my_new_numbers)
i know its probably nonsense what I wrote, I just was trying to change this code, that in fact does work:
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
my_new_numbers = []
for x in my_list:
my_new_numbers.append(x * x)
print(my_new_numbers)
Would like to have a solution only with basic operators and loops and lists, no import etc.
Thanks a lot