Your semi-functional code returns other values ββbecause records such as:
"Normal UK project" : "1",
.. then "1" in v checks if the string contains the character "1", while with elements of the type:
"Nordic project" : ["11","12","13","14"],
.. then it will check if the list contains the element "1".
The in operator works both in rows and in lists, but in a different way:
>>> "1" in "123" True >>> "1" in ["123", "blah"] False >>> "1" in ["1", "blah"] True
Ideally, your data will be more consistent - all lists or all rows:
countries = { "Normal UK project" : ["1"], "UK Omnibus project" : ["1-Omni"], "Nordic project" : ["11","12","13","14"], "German project" : ["21"], "French project" : ["31"] } for k, v in countries.items(): if "1" in v: print k
dbr
source share