Validate dicts in Python
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: i looking for tool, or examples to/how to validate dictionaries in python. For example, i have dict: test = { 'foo' : 'bar' , 'nested' : { 'foo1' : 'bar1' , 'foo2' : 'bar2' } } And now i must validate it. Lets say, value for key foo must be boolean False or non-empty string. Next, if key foo1 have value bar1 , that key foo2 must be int in range 1..10 . I wrote simple function to do this, but this is not what i exactly want. Yea, sure, i can test every single item in dict with if..else , but if dict have >50 elements, then it is a