Message148567
Given that we typically need at least 4 bytes just for the PyObject * pointer for each item in a list, I guess real lists are safe.
But how about list-like objects, implementing __len__ and __getitem__? The following appears to run forever on my machine:
class SquaresList(object):
def __init__(self, length):
self._length = length
def __len__(self):
return self._length
def __getitem__(self, index):
if not 0 <= index <= self._length:
raise IndexError
return index**2
import bisect, sys
squareslist = SquaresList(sys.maxsize)
print bisect.bisect(squareslist, (sys.maxsize - 3)**2) |
|
Date |
User |
Action |
Args |
2011-11-29 14:03:40 | mark.dickinson | set | recipients:
+ mark.dickinson, tim.peters, rhettinger, Voo |
2011-11-29 14:03:40 | mark.dickinson | set | messageid: <1322575420.88.0.360814868035.issue13496@psf.upfronthosting.co.za> |
2011-11-29 14:03:40 | mark.dickinson | link | issue13496 messages |
2011-11-29 14:03:40 | mark.dickinson | create | |
|