#๐Ÿ”’ Can someone help me with this error.

20 messages ยท Page 1 of 1 (latest)

teal isle
#

Im trying to get the oldest year in my json file but it does not work. Can anyone help me?

wooden mountainBOT
#

@teal isle

Python help channel opened

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.

mellow roost
#

Show your json

teal isle
#

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)
mellow roost
#

For the oldest year you should collect all the years from each dict in the list and then use min

teal isle
#

i still get the same error when i do that

mellow roost
#

How did you change your code to do what i suggested?

teal isle
#

this is what you said right

#

@mellow roost

mellow roost
#

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

rain thistle
#

you can probably just do max(movie, key=lambda x: x['year'])

wooden mountainBOT
#
Python help channel closed

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.