Python: Range() maximum size; dynamic or static?
Look at get_len_of_range and get_len_of_range_longs in the builtin module source
Summary: You'll get an OverflowError if the list has more elements than can be fit into a signed long. On 32bit Python that's 2**31 - 1
, and on 64 bit Python that's 2**63 - 1
. Of course, you will get a MemoryError even for values just under that.
Bolster
I'm a PhD student of Electronics & Software Engineering at Queen's University Belfast's Institute of Electronics, Comminucations, and Information Technology (ECIT). I want to get more involved in FOSS (as I've been using FOSS for years now). I try to document my experiments and experiences on my blog so check it out. Also an active founder of QUESTS (Queen's University, Engineering, Science, and Technology Society) and Farset Labs in Belfast, Northern Ireland
Updated on June 24, 2022Comments
-
Bolster about 2 years
I'm quite new to python, so I'm doing my usual of going through Project Euler to work out the logical kinks in my head.
Basically, I need the largest list size possible, ie range(1,n), without overflowing.
Any ideas?