使用 Python 2.6,有没有办法在一个语句中检查序列的所有项目是否等于给定值?
[pseudocode]
my_sequence = (2,5,7,82,35)
if all the values in (type(i) for i in my_sequence) == int:
do()
而不是,说:
my_sequence = (2,5,7,82,35)
all_int = True
for i in my_sequence:
if type(i) is not int:
all_int = False
break
if all_int:
do()