Is every number in a list in a range?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Mar 6 00:21:02 CET 2007


MonkeeSage a écrit :
> On Mar 5, 1:03 pm, "Steven W. Orr" <ste... at syslang.net> wrote:
> 
>>I have a list ll of intergers. I want to see if each number in ll is
>>within the range of 0..maxnum
> 
> 
> How about:
> 
> maxnum = 100
> inlist = range(90, 120)
> for i in [i for i in inlist if i >= 0 and i <= maxnum]:

                               if 0 <= i <= maxnum

>     # do something with i, it's in the valid range
>     print i

But I guess Steven is able to come up with such a solution by itself !-)




More information about the Python-list mailing list