我宣布了这本词典:
person ={'name':[],'age':[], 'adress':[]}
是否有一个功能可以检查它是否具有值?
例如:
person = { 'name':[], 'age':[], 'adress':[] }
->返回空,如果
person = { 'name':['Paul'], 'age':[25], 'adress':['xxxxx'] }
->返回不为空
答案 0 :(得分:2)
您可以这样做:
if all(person.values()):
# not empty lists
elif not any(person.values()):
# all empty
else:
# some empty
答案 1 :(得分:1)
我认为这是为您提供的解决方案,
operator>>
答案 2 :(得分:0)
如果列表不是空列表,则将其视为真实列表。也就是说,
if []:
print('Yes')
else:
print('No')
输出No
。
还有一个内置函数any
,该函数以Iterable作为参数,如果任何产生的值是真实的,则返回True
。因此,如果您想知道任何列表中是否包含任何值,可以这样做
any(person.values())