I have some Python dictionaries like this:
A = {id: {idnumber: condition},....
e.g.
A = {1: {11 : 567.54}, 2: {14 : 123.13}, .....
I need to search if the dictionary has any idnumber == 11 and calculate something with the condition. But if in the entire dictionary doesn’t have any idnumber == 11, I need to continue with the next dictionary.
This is my try:
for id, idnumber in A.iteritems():
if 11 in idnumber.keys():
calculate = ......
else:
break
You’re close.
If you need to know how many
11s there are as keys in the innerdicts, you can:This works because a key can only be in each
dictonce so you just have to test if the key exits.inreturnsTrueorFalsewhich are equal to1and0, so thesumis the number of occurences ofidnum.