The Python Oracle

Why is "1000000000000000 in range(1000000000000001)" so fast in Python 3?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Jungle Looping

--

Chapters
00:00 Question
01:55 Accepted answer (Score 2944)
05:12 Answer 2 (Score 1143)
08:36 Answer 3 (Score 480)
11:35 Answer 4 (Score 192)
12:51 Thank you

--

Full question
https://stackoverflow.com/questions/3008...

Question links:
[an object type in Python 3]: https://docs.python.org/3/library/stdtyp...
[Martijn Pieters's answer]: https://stackoverflow.com/a/30081318/243...
[abarnert's first answer]: https://stackoverflow.com/a/30081894/243...
[abarnert's other answer]: https://stackoverflow.com/a/30088140/243...
[by poke]: https://stackoverflow.com/a/30081467/243...
[by wim]: https://stackoverflow.com/a/30081470/243...

Accepted answer links:
[sequence object]: https://docs.python.org/3/library/collec...
[object.__contains__]: https://docs.python.org/3/reference/data...
[range()]: https://docs.python.org/3/library/stdtyp...
[Python issue]: http://bugs.python.org/issue1766304

Answer 3 links:
[source]: https://github.com/python/cpython/blob/c...

Answer 4 links:
[the source]: https://hg.python.org/cpython/file/7f8cd...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #performance #python3x #range #pythoninternals

#avk47