使用all()内置函数检查字典键

时间:2019-03-28 09:42:00

标签: python python-3.x

在字典中是否存在使用all()函数检查某个键的任何方法,仅在一行代码中。例如:

d = {"x": 1, "y":2}
if all("x" and "y" in d): # this way didn't work
   # do-something

0 个答案:

没有答案