1、
@classmethod def get_dict_value(cls, in_dict, target_key, results=[], not_d=True): """ in_dict:字典嵌套字典内容 target_key:需要筛选的value results:筛选后返回列表 data_list:通过正则筛选需要的内容,return """ for key in in_dict.keys(): # 迭代当前的字典层级 data = in_dict[key] # 将当前字典层级的第一个元素的值赋值给data # 如果当前data属于dict类型, 进行回归 if isinstance(data, dict): IOS_image.get_dict_value(data, target_key, results=results, not_d=not_d) # 如果当前键与目标键相等, 并且判断是否要筛选 if key == target_key and isinstance(data, dict) != not_d: results.append(in_dict[key]) data_list = list(filter(lambda x: re.match(r'2023-*|2024-*', x) != None, results)) # print(data_list) return data_list
标签:Python,list,results,嵌套,dict,key,data,字典 From: https://www.cnblogs.com/jc-home/p/17639734.html