homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Voo, mark.dickinson, rhettinger, tim.peters
Date 2011年11月29日.14:03:40
SpamBayes Score 1.157578e-05
Marked as misclassified No
Message-id <1322575420.88.0.360814868035.issue13496@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2011年11月29日 14:03:40mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, Voo
2011年11月29日 14:03:40mark.dickinsonsetmessageid: <1322575420.88.0.360814868035.issue13496@psf.upfronthosting.co.za>
2011年11月29日 14:03:40mark.dickinsonlinkissue13496 messages
2011年11月29日 14:03:40mark.dickinsoncreate

AltStyle によって変換されたページ (->オリジナル) /