Reputation: 173
I am trying to save the amount of points each player(p) scored, in each game(g), to a dictionary keyed by their opponent. I am getting a syntax issue in the following code:
opponents = {}
for p in range(len(league_data['elements'])):
for g in range(len(game_data[str(league_data['elements'][p]['id'])]['history'])):
#skip games where the player played 0 minutes
if game_data[str(league_data['elements'][p]['id'])]['history'][g]['minutes'] == 0: continue
opp = team_list[game_data[str(league_data['elements'][p]['id'])]['history'][g]['opponent_team']
points = game_data[str(league_data['elements'][p]['id'])]['history'][g]['total_points']
opponents.setdefault(opp, [0,0])[0] += points
opponents[opp][1] += 1
I'm getting the error on the following line:
points = game_data[str(league_data['elements'][p]['id'])]['history'][g]['total_points']
^
SyntaxError: invalid syntax
But I can't see the problem. Also if I write the line out in a seperate cell and print points
it works fine.
Upvotes: 0
Views: 36
Reputation: 96
It complains about this line because the line above isn't fully contained. The line above implicitly continues the [
to the next line where it encounters an assignment (which is invalid here).
Upvotes: 3