'Syntax Error while creating a football player Python Dictionary
I was wondering if any of you would be able to assist. I'm fairly new to python and I'm getting a syntax error with this embedded list item:
myDict = {
"Date": "20210807",
"KickOff": "15:00",
"Result": "2-1",
"Opposition": "Wigan",
"Home/Away": "Home",
"Player":
[ #syntax error on this line
"Lee Burge":
[
"Minutes Played": "90",
"Shirt Number": "1",
"Position": "G",
"Match Rating": "6.3",
"Captain": "N",
"Substitute": "N",
"Offsides": "0",
"Shot Total": "0",
"Shots On Target": "0",
"Goals": "0",
"Goals Conceded": "1",
"Assists": "0",
"Saves": "2",
"Pass Total": "26",
"Key Passes": "0",
"Accurate Passes": "14",
"Pass Accuracy": "53.85",
"Tackles Total": "0",
"Blocks": 0,
"Interceptions": 0,
"Duels Total": 1,
"Duels Won": 0,
"Dribble Attempts": 0,
"Dribble Successful": 0,
"Dribble Past": 0,
"Fouls Drawn": 0,
"Fouls Committed": 0,
"Red Card": 0,
"Yellow Card": 0,
"Penalties Won": 0,
"Penalties Committed": 0,
"Penalties Scored": 0,
"Penalties Missed": 0,
"Penalties Saved": 0
]
]
}
Thanks in advance
Solution 1:[1]
At the point you marked as a syntax error, you open with a list but you are using dictionary syntax (by writing "Lee Burge":
). I assume you actually want nested dictionaries:
myDict = {
"Date": "20210807",
"KickOff": "15:00",
"Result": "2-1",
"Opposition": "Wigan",
"Home/Away": "Home",
"Player":
{ # Note that this is a dictionary now
"Lee Burge":
{ # Here, you also have a dictionary
"Minutes Played": "90",
"Shirt Number": "1",
"Position": "G",
"Match Rating": "6.3",
"Captain": "N",
"Substitute": "N",
"Offsides": "0",
"Shot Total": "0",
"Shots On Target": "0",
"Goals": "0",
"Goals Conceded": "1",
"Assists": "0",
"Saves": "2",
"Pass Total": "26",
"Key Passes": "0",
"Accurate Passes": "14",
"Pass Accuracy": "53.85",
"Tackles Total": "0",
"Blocks": 0,
"Interceptions": 0,
"Duels Total": 1,
"Duels Won": 0,
"Dribble Attempts": 0,
"Dribble Successful": 0,
"Dribble Past": 0,
"Fouls Drawn": 0,
"Fouls Committed": 0,
"Red Card": 0,
"Yellow Card": 0,
"Penalties Won": 0,
"Penalties Committed": 0,
"Penalties Scored": 0,
"Penalties Missed": 0,
"Penalties Saved": 0
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | nonDucor |