I have a list of integers that I run through a for loop to detect if two of the combined elements are equal to another variable t . So if t was equal to 10 , and I had a list of intergers: l = [1,2,3,4,5,8,9] , then the function should print all the different combinations of numbers (1,9) , (2,8) .
I feel like I'm almost there, but something strange happens to the list when I use the .pop() function. The code below is used to display all combinations of numbers that need to be calculated, but every other item in the list is skipped.
l = [1,2,5,8,13,15,26,38] c = 10 for i in l: first = i l.pop(0) for x in l: second = x print(first,second)
Here is the result:
1 2 1 5 1 8 1 13 1 15 1 26 1 38 5 5 5 8 5 13 5 15 5 26 5 38 13 8 13 13 13 15 13 26 13 38 26 13 26 15 26 26 26 38
Please note that tags 2 , 8 , 15 and 38 skipped. I use l.pop , so the second for loop will not use the original value, and the next iteration can continue to iterate the next item in the list.
source share