2021年1月23日星期六

Key Error while appending data into dictionary of list in Python

I am trying to create a dictionary where the key values are stored in a list like this :

data={      "key_value":["h1","h2","h3"],      "key_value2":["h11","h21","h31"],  }  

While adding elements to this list of dicts, I am using this function :

data[book_name].append(highlight)  

But this gives me a key error KeyError: 'Key_value ' Why is this happening?

https://stackoverflow.com/questions/65867224/key-error-while-appending-data-into-dictionary-of-list-in-python January 24, 2021 at 12:48PM

没有评论:

发表评论