I believe this would do what you want.
for i in G:
if 'noone' in G[i]:
G[i].pop('noone')
What you have here (G) is indeed a dictionary, but more specifically, it's a dictionary whose values are also dictionaries. thus, when we iterate through all the keys in G (for i in G
), each key's corresponding value (G[i]
) is a dictionary. You can see this for yourself if you try running:
for i in G:
print(G[i])
So what you really want to do is pop from each dictionary in G. That is, for each G[i], you want to remove 'noone' from those "sub"-dictionaries, not the main top one.
P.S.: if you really want to take advantage of python's convenience, you can even write simply
for i in G:
G[i].pop('noone', None)
By using the second argument into pop, you don't even have to check to see if 'noone' is a key in G[i] first because the pop method will not raise an exception. (if you tried this two-liner without the second argument, you'd get an error for all sub-dicts that don't have 'noone' in them).