eli*_*gro 10 python dictionary list
{'action_name':'mobile signup',
'functions':[{'name':'test_signUp',
'parameters':{'username':'max@getappcard.com',
'password':'12345',
'mobileLater':'123454231',
'mobile':'1e2w1e2w',
'card':'1232313',
'cardLater':'1234321234321'}}],
'validations':[
{'MOB_header':'My stores'},
{'url':"/stores/my"}]}
Run Code Online (Sandbox Code Playgroud)
我想得到这个dict的所有键和值作为一个列表(超出它们是dict或数组的值)
打印结果应该是这样的:
action name = mobile signup
name = test_signUp
username : max@getappcard.com
password : 12345
mobileLater: 123454231
mobile : 1e2w1e2w
card : 1232313
cardLater : 1234321234321
MOB_header : My stores
Run Code Online (Sandbox Code Playgroud)
您可能希望使用递归函数来提取所有key, value对.
def extract(dict_in, dict_out):
for key, value in dict_in.iteritems():
if isinstance(value, dict): # If value itself is dictionary
extract(value, dict_out)
elif isinstance(value, unicode):
# Write to dict_out
dict_out[key] = value
return dict_out
Run Code Online (Sandbox Code Playgroud)
这种东西.我来自C++背景,所以我不得不谷歌所有的语法.