I'm struggling to get an understanding of how Python treats for loops that come after variables. I think it might have something to do with iterables/iterators in Python, but I'm not sure I really understand the usage. Basically in the following code I understand the math of why it works to produces the combinations of the variables, but I don't get how this is a valid way to create a list. In my experience with other languages, for loops always cone before the expressions and are properly nested when there is more than one.
temp = [('CH', 'AG', 'ME', 'GS')]
[(temp[i],temp[j]) for i in range(len(temp)) for j in range(i+1, len(temp))]
#produces:[('CH', 'AG'), ('CH', 'ME'), ('CH', 'GS'),
#('AG', 'ME'),('AG', 'GS')('ME', 'GS')]
Can anyone explain what's going on here?