gpt4 book ai didi

python - 字典有列表中的键

转载 作者:太空狗 更新时间:2023-10-29 21:13:41 25 4
gpt4 key购买 nike

我如何确定是否有任何列表元素是字典的键?直接的方法是,

for i in myList:
if i in myDict:
return True
return False

但是有没有更快/更简洁的方式呢?

最佳答案

#!python
any(x in MyDict for x in MyList)
set(MyList).intersection(MyDict)

关于python - 字典有列表中的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1737778/

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