1

error enter image description here

python code

I am getting an key error even when there's a key present.

print (dict_month[0:4])

[{'January': 'Sun'}, {'January': 'Sun'}, {'January': 'Sun'}, {'January': 'Sun'}]

'January' in dict_month

False

'january' in dict_month

False

Chris D'mello
  • 135
  • 2
  • 9

1 Answers1

0

Simple one liner :

>>> any(['January' in ele for ele in l])

#driver values :

IN : l = [{'January': 'Sun'}, {'January': 'Sun'}, {'January': 'Sun'}, {'January': 'Sun'}]

OUT : True

The problem with your approach was as A.Joly mentioned, that you have a list of dictionary. Your approach would have been correct for a dictionary.

Kaushik NP
  • 6,446
  • 8
  • 30
  • 57