I'am working on a exercise and I can't see where I get it wrong. I'm trying to add the indexes of the sum of two numbers to a list, but instead of getting the indexes, I'm actually getting the numbers. Here is my code, and many thanks in advance for your precious help and time.
a_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
target_list = []
counter = 0
for i in range(len(a_list)):
for j in a_list:
if i + j == 10:
target_list.append((a_list.index(i), a_list.index(j)))
counter += 1
print(target_list)
how can I do it with list comprehension. Thank you again and again.
countervariable serve? It is also not entirely clear what output you expect since the indeces are equal to the values in your example. Pls chose more general sample data and show the expected output.enumerate()