我有一个字典的例子:
dictionary = {Bay1: [False,False,True],
Bay2: [True,True,True],
Bay3: [True,True,False],
Bay4: [False,False,False] }
我要做的是通过检查每个间隔(Bay1,Bay2…)来浏览字典,看看哪个有一个数组,其中所有内容都是False
。对于这个例子,我希望它返回'Bay4'
其次,我希望能够通过使用循环检查每个间隔中的False
和True
。换句话说,您可以想象True
表示“预订”,而False
表示免费或“未预订”。我希望能够检查,为每个海湾,并提出了一个良好的,易于阅读的格式给用户
第一部分
返回值为all
False
的键:第二部分
每个
bay
的True
(已预订)和False
(未预订)计数数:你应该提供更多的信息
无论如何,如果我理解了您的问题,您可以在
for
循环中使用any()
和all()
:相关问题 更多 >
编程相关推荐