Greater than problem

This was a Codeacademy list comprehension on Greater Than. I was stuck and looked at the code solution.

nested_lists = [[4, 8], [16, 15], [23, 42]]
greater_than = [list1 > list2 for [list1, list2] in nested_lists]
print (greater_than)

In the code solution, this line was greater_than = [E1 > E2 for [E1, E2] in nested_lists]

I changed to list1 and list2. My reasoning was to find out what effect that would have on it because E1 and E2 arent declared anywhere. How does Python know (or care) what you refer to those list items as and why did changing it still work?
Thank you in advance.

just like with any other for loop:

for item in the_list:

the iterator (item) gets declared in the loop, python is clever enough to assign the values of the list to the iterator you defined (named).

1 Like