标签:else pytho 规模 val 问题 字典 min 字段 之间
1.描述:
2.递归函数特性:
3.实例说明
#相加计算,递归方式 def fact(n): if n > 0: return fact(n-1) + n else: return 0 print(fact(5))
4.实例应用
#找出接口报文中某个字段的值 queryUserList = { "code": "200", "msg": "查询用户成功!", "model": { "user1": { "userAccount": "17779828882", "userName": "zhengying2", "userMobile": "17779828882", "userEmail": "17779828882@qq.com" }, "user2": { "userAccount": "17779828881", "userName": "zhengying1", "userMobile": "17779828881", "userEmail": "17779828881@qq.com" }, "user3": { "userAccount": "17779828880", "userName": "zhengying0", "userMobile": "17779828880", "userEmail": "17779828880@qq.com" }, "user4": { "userAccount": "admin", "userName": "admin", "userMobile": "", "userEmail": "" }, "pages": 1 } } #代码如下 values = [] def get_value(getkey,dict1): if isinstance(dict1,dict): #验证入参格式是否为字典 for k,v in dict1.items(): #取出所以的键值对 if k == getkey: #判断所拿到的键是否是预期传入的键 values.append(v) get_value(getkey,v) #进行递归 get_value("userEmail",queryUserList) print(values)
标签:else pytho 规模 val 问题 字典 min 字段 之间
原文地址:https://www.cnblogs.com/ZhengYing0813/p/12384760.html