if number is 1-2, 4 or 6-8 or 12-28, 30, 32...

Cliff Wells logiplexsoftware at earthlink.net
Tue Jun 11 20:11:01 CEST 2002


On Tue, 11 Jun 2002 08:50:18 -0500
Skip Montanaro wrote:

> You could also fold the int case into the tuple case (making it a bit more
> uniform), but at a slight cost in performance if you have lots of ints.  In
> this case, all the try/except statement is responsible for is setting s and
> e:
> 
>     def isin(n, ranges):
>         for r in ranges:
>             try: 
>                 s, e = r
>             except TypeError:
>                 s, e = n, n
>             if s <= n <= e:
>                 return 1
>         return 0

I do think this is a bit clearer, however I know you meant to write

except TypeError:
    s, e = r, r



-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308





More information about the Python-list mailing list