Is every number in a list in a range?

Matimus mccredie at gmail.com
Tue Mar 6 02:16:21 CET 2007


On Mar 5, 1:34 pm, "Matimus" <mccre... at gmail.com> wrote:
> On Mar 5, 11:03 am, "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
>
> > I can write it but I was wondering if there's a better way to do it?
>
> > TIA
>
> > --
> > Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
> > happened but none stranger than this. Does your driver's license say Organ ..0
> > Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
> > individuals! What if this weren't a hypothetical question?
> > steveo at syslang.net
>
> I would probably do something using max and min functions like this:
>
> seq = [...] # your list
>
> if min(seq) >= 0 && max(seq) <= MAXNUM:
>  do stuff

OOps... I've been writing too much C++ lately (or too little python).
That should read:

if min(seq) >= 0 and max(seq) <= MAXNUM:
    do_stuff()




More information about the Python-list mailing list