#๐ Can someone help me with this error.
20 messages ยท Page 1 of 1 (latest)
@teal isle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Show your json
this is not the whole json
there are much more
this one is for testing
with open(os.path.join(sys.path[0], file)) as json_file:
inhoud = json.load(json_file)
for movie in inhoud:
if movie['title'] == "Gladiator":
movie['year'] = 2001
laatste = max(movie['year'], key=lambda x: x['year'])
print(laatste)
with open(os.path.join(sys.path[0], file), 'w') as json_output:
json.dump(inhoud, json_output, indent=4)
For the oldest year you should collect all the years from each dict in the list and then use min
i still get the same error when i do that
How did you change your code to do what i suggested?
movie[" year"] there is a single year for each movie
Not all the years
Collect each year into a new list and then use min on that list
you can probably just do max(movie, key=lambda x: x['year'])
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.