Some syntactic sugar proposals

Tim Chase python.list at tim.thechases.com
Thu Dec 2 13:18:42 EST 2010


On 12/02/2010 10:39 AM, Mark Dickinson wrote:
> On Nov 15, 12:46 pm, Tim Chase<python.l... at tim.thechases.com>  wrote:
>> On 11/15/2010 12:39 AM, Dmitry Groshev wrote:
>>
>>> x in range optimisation
>>
>> I've often thought this would make a nice O(1)-test lookup on an
>> xrange() generator.
>
> An O(1) test for 'x in<range_object>' is implemented in Python 3.2,
> at least provided that x has type 'int', 'long' or 'bool'.  (If x is
> an instance of a subclass of int or long, then there's a risk that the
> semantics of the membership test have been changed by an explicitly
> overridden __eq__, so Python wimps out and falls back to the O(n)
> algorithm in that case.)

Drat, bested again by the python time-machine.  Thanks for 
bringing that to my attention.

-tkc






More information about the Python-list mailing list