更新时间:2023-11-28 16:42:04
您必须使用for
,简单的if
不足以检查一组未知的列表:
You'll have to use a for
, a simple if
is not enough to check an unknown set of lists:
for key in mydict.keys():
if item in mydict[key]:
print key
没有显式for
语句的方法可能是这样的:
An approach without an explicit for
statement would be possible like this:
foundItems = (key for key, vals in mydict.items() if item in vals)
返回与item
关联的所有键.但是在内部,仍然存在某种迭代.
which returns all keys which are associated with item
. But internally, there's still some kind of iteration going on.