Skip to content
Advertisement

Key Error even though key IS in dictionary? [closed]

Dictionary: section of dictionary

My Code: code

Error says: 3

So how come the date key works fine but for freq it fails?

ps. my first time posting, so am very sorry for the sloppy structure of the post

Advertisement

Answer

This can only happen when one of your day is missing the freq parameter.

Try catching the day in which the error is happening. Then manually check that particular entry.

date_list = []
frequency_list = []
try:
    for i in obj:
         date = obj[i]["date"]
         frequency = obj[i]["freq"]

         date_list.append(date)
         frequency_list.append(frequency)
except:
    print(i)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement