[Solved] Unclear python syntax [duplicate]


The for loops are nested, from left to right. You can write it out as regular loops like this:

words = []
for line in open('words.txt', 'r'):
    for word in line.split():
        words.append(word)

So the expression before the for loops is the final value added to the produced list, and all the for loops (and any if tests) are executed nested inside the preceding loop or test.

So, yes, for each line in the opened file, the line is split and the resulting words from those lines are added to the list being built.

solved Unclear python syntax [duplicate]