[Python-ideas] Pass a function as the argument "step" of range()

Andrew Barnert abarnert at yahoo.com
Mon Jul 6 07:00:10 CEST 2015

On Jul 5, 2015, at 09:15, Pierre Quentel <pierre.quentel at gmail.com> wrote:
> 2015-07-03 12:29 GMT+02:00 Andrew Barnert <abarnert at yahoo.com>:
>> On Jul 2, 2015, at 08:53, Pierre Quentel <pierre.quentel at gmail.com> wrote:
>> >
>> > It's true, but testing that an integer is a range is very rare : the pattern "if X in range(Y)" is only found once in all the Python 3.4 standard library
>> Given that most of the stdlib predates Python 3.2, and modules are rarely rewritten to take advantage of new features just for the hell of it, this isn't very surprising, or very meaningful.
> Then most of the stdlib also predates Python 1.5.2 (the version I started with) :
> Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> 4 in range(10)
> 1
> >>> 

Well, a good chunk of the stdlib does predate 1.5.2, but not nearly as much as predates 3.2...

At any rate, as I'm sure you know, that works in 1.5.2 because range returns a list. Try it with range(1000000000) and you may not be quite as happy with the result--but in 3.2+, it returns instantly, without using more than a few dozen bytes of memory.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150705/b18ec970/attachment.html>

More information about the Python-ideas mailing list