Is every number in a list in a range?

MonkeeSage MonkeeSage at gmail.com
Tue Mar 6 04:13:05 CET 2007


On Mar 5, 9:03 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Maybe I didn't undrestand the question.  Say maxnum is 30 in your
> example above.  Then as soon as 46 is seen, you can stop checking, I
> thought.

Yes, as long as 29 doesn't follow 46.

inlist = [1, 5, 23, 46, 29, 21]

If you want to preserve the items after 46, then you can't just bail
when you see 46. You need to keep looking at the following values and
comparing them against the boundry conditions. If the the input is
sequential, then this isn't a problem, as all items above 46 are out
of range....but if the input is arbitrary, then you have to look at
each index individually as you know. So it really comes down to if the
data set is ordered or arbitrary as to which approach is more
efficient.

Regards,
Jordan




More information about the Python-list mailing list