【发布时间】:2020-03-03 10:40:30
【问题描述】:
我有一本字典 dict_matches 有 2 个内部字典。
dict_match的结构如下:
dict_match = {Query_ID:{Function_ID:{DB_ID:[func_ID]}}}
在顶级键 Query_ID 中,我循环遍历这些并将它们与完全独立的字典 query_count_dict 中的键进行比较,以确定键的重叠。
在这个循环中,我还导航到dict_matches 中的基本字典,以查看主密钥与哪些键DB_ID“匹配”。我的问题是,与最顶层键 Query_ID 对应的低层键 DB_ID 可以复制(我只想查看唯一键)。我尝试使用 set() 方法,但这实际上将字符串键拆分为它们的字符组件,并为每个较低级别的键打印唯一字符。任何帮助表示赞赏!
见下方代码
for k,v in dict_match.items():
if k in query_count_dict.keys():
print(k)
detection_query.append(k)
print(len(dict_match[k])/int(query_count_dict[k]))
if type(v) is dict:
recursive_items(v)
recursive_items 是一个导航到基本字典的函数:
def recursive_items(dictionary):
for k, v in dictionary.items():
if type(v) is dict:
recursive_items(v)
else:
print(set(k))
【问题讨论】:
标签: python dictionary nested