【发布时间】:2010-11-21 06:48:57
【问题描述】:
我有一本字典,我们称它为myDict,在 Python 中,它包含一组类似的字典,它们都具有条目“turned_on : True”或“turned_on : False”。我想删除 myDict 中所有关闭的条目,例如其中“turned_on : False”。在 Ruby 中,我会做这样的事情:
myDict.delete_if { |id,dict| not dict[:turned_on] }
我应该如何在 Python 中做到这一点?
【问题讨论】:
-
id2中有错字吗?你实际上没有密钥turned_off,是吗? -
是的。感谢您指出!
标签: python ruby dictionary