Is every number in a list in a range?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Mar 5 17:22:10 EST 2007


Steven W. Orr:
> I have a list ll of intergers. I want to see if each number in ll is
> within the range of 0..maxnum

One possible nice solution (Python V.2.5):

data = [1, 20, 22, 11, 400, 7]
maxnum = 100
print all(0 <= x <= maxnum for x in data)
maxnum = 1000
print all(0 <= x <= maxnum for x in data)

Bye,
bearophile




More information about the Python-list mailing list