我是python的初学者。
我正在尝试从此字典中删除所有“noone:0”,因此它看起来与下面相同,但没有任何“noone:0”:
G = {'a': {'b': 10, 'c': 8, 'd': 3, 'noone': 0, 'e': 3}, 'f': {'g': 7, 'c': 5, 'h': 5, 'i': 2, 'j': 4, 'noone': 0, 'l': 2}}
Run Code Online (Sandbox Code Playgroud)
我搜索并找到了我应该实现它的所有方法,但找不到有效的方法。我试过这个无济于事:
for i in G:
if str(G[i]) == 'noone':
G.pop('noone', None)
Run Code Online (Sandbox Code Playgroud)