range() is not the best way to check range?

Paul Boddie paul at boddie.org.uk
Tue Jul 18 13:34:01 EDT 2006


Grant Edwards wrote:
>
> It's unclear what you're referring to as "the range".

The notion of something describing a range of values which can be
expanded to a list or, of relevance here, whose boundaries can be
tested efficiently.

> Perhaps you're thinking of a slice?  Somethign like
>
>   if  (0:10000).contains(x):

Did you mean...?

(0:10000) # SyntaxError
slice(0, 10000).contains(x) # AttributeError
3 in slice(0, 10000) # TypeError

Something like this might suffice if slice could have a __contains__
method or if people thought of slices as natural things to test
against. Perhaps we could ask the original questioner why they chose to
use range in such a way - it might indicate a background in languages
which encourage the construction of ranges and their use in comparisons
- although being told to RTFM may have scared them off.

Paul




More information about the Python-list mailing list