![](/img/trans.png)
[英]Function to check list of lists have all integer elements between 0 and n and lists are all of given length?
[英]How to check if all elements in a list have length of 5?
假设我有一个 lst = ["John", "Jack", "Elizabeth", "Smith"]
我想使用 all 方法检查所有这些名称是否少于 5 个字符。 我在下面尝试的两种方法都不起作用。
if len(all(lst)) < 5:
return "Everyone's names have less than five characters"
if all(len(lst)) < 5:
return "Everyone's names have less than five characters"
我确实希望使用 all 方法。 请帮忙!
lst = ["John", "Jack", "Elizabeth", "Smith"]
if all(len(name) < 5 for name in lst):
print('all names have length of 5 characters')
else:
print('not all of names have length of 5 characters')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.