gpt4 book ai didi

python - 如何提取 python Dict 值的每个可能值以列出

转载 作者:太空宇宙 更新时间:2023-11-04 07:26:02 25 4
gpt4 key购买 nike

DICTA={'bw':['BW','VW'],'b':['BB','VV'],'a':['AA']}
DICTB={'yn':['$YN','$YNN'],'ye':['$YE','A$Y'],'y':['Y$']}

如何提取 2 Dict 的所有可能值

["BWYN","VWYN","BBYN","VVYN","AAYN","BWYNN","VWYNN","BBYNN","VVYNN","AAYNN",
"BWYE","VWYE","BBYE","VVYE","AAYE","ABWY","AVWY","ABBY","AVVY","AAAY",
"YBW","YVW","YBB","YVV","YAA"]

PS:顺序无关紧要

PPS:不是作业,但想知道如何有效地实现它。

最佳答案

以下基本主题的许多可能的小变体:

print [y.replace('$', x)
for y in (v for y in DICTB.values() for v in y)
for x in (v for y in DICTA.values() for v in y)
]

关于python - 如何提取 python Dict 值的每个可能值以列出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1857820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com