Jed Rembold
November 14, 2025
Three of the below expressions are valid; one is not. Which one would return an error?
{'A': {'B': (1,2)}, 'C': 3}{1, 2, (3,4), 5 }[{'Alpha': 1, 'Omega': 26}, {2, 3, 4, 5}]{['A', 'B']: {1, 2}}| Name | Class | Q1 | Mid | Q3 | Final |
|---|---|---|---|---|---|
| Sally | Python | A | B | B | A |
| Jake | Python | B | B | B | C |
| James | Astro | B | B | A | |
| Lily | Astro | A | A | B | |
| Ben | Python | C | B | B | A |
{
"Python": {
"Sally": ["A", "B", "B", "A"],
"Jake": ["B", "B", "B", "C"],
"Ben": ["C", "B", "B", "A"]
},
"Astro": {
"James": ["B", "B", "A"],
"Lily": ["A", "A", "B"]
}
}
json
json.load(|||file handle|||)
json.dump(|||data_object|||, |||file handle|||)
with open(|||filename|||) as |||fhandle|||:
syntaxTo read a JSON file into a variable
data:
import json
with open('file.json') as fh:
data = json.load(fh)To write a variable with complex structure out to a JSON file:
import json
with open('file.json', 'w') as fh:
json.dump(data, fh)[1, 2, 3,] is perfectly
fine in Python, but illegal in JSON