Why Are Membership Tests So Fast for range() in Python?
In Python, range() is most commonly used in for loops to iterate over a known range of numbers. But that’s not all it can do! There are other interesting uses of range(). For example, you can pick out elements of a range or check whether a given number belongs to a range of numbers. The latter operation is known as a membership test. Python’s range() objects support most of the operations that you’ve come to expect from lists. For example, […]
Read more