Is every number in a list in a range?

Paul Rubin http
Tue Mar 6 02:24:22 CET 2007

"Steven W. Orr" <steveo at> writes:
> I have a list ll of intergers. I want to see if each number in ll is
> within the range of 0..maxnum
> I can write it but I was wondering if there's a better way to do it?

if all(0 <= x <= maxnum for x in ll): ...

This genexp is better than a loop because it bails out immediately
if it finds an out-of-range x.

More information about the Python-list mailing list