faqts : Computers : Programming : Languages : Python : Snippets : Lists

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 4 people (50%) answered Yes
Recently 1 of 3 people (33%) answered Yes

Entry

Infinite lists

Jul 5th, 2000 10:03
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 304, Fredrik Lundh


"""
Packages: basic_datatypes.lists
"""
"""
> > It always does a linear search. I think this is intended,
> > and also should be so since "in" can scan infinite sequences.
> [GC]  
> Infinite sequences? How?
try this:
"""
class InfiniteRange:
    def __getitem__(self, index):
        return index # never ends
x = InfiniteRange()
print 10 in x
print 100 in x
print 1000 in x
print 10000 in x
print 100000 in x
# etc
"""
the exact value of infinity is platform dependent,
of course...
"""