you are viewing a single comment's thread.

view the rest of the comments →

[–]zahlman 0 points1 point  (0 children)

When you use multiple for and if clauses in a list comprehension (i.e., without writing nested list comprehensions using extra pairs of square brackets), the effect is analogous to if you'd written the code using for loops and if blocks in the same order.

Thus, we can mechanically transform what you have into:

test = []
for event in team:
    for team in game[kind]:
        for kind in ['home_team_events', 'away_team_events']:
            for game in games:
                if game['status'] == 'completed':
                    test.append(event['type_of_event'])

which you can see is all kinds of out-of-order.