In Python, is there some short way to do something like
“for i in range(n)”
when n is too big for Python to actually create the array range(n)?
(short because otherwise I’d just use a while loop)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use xrange()… although that is restricted to “short” integers in CPython:
I don’t know whether that restriction also applies to other implementations (or which ones) – but there’s a workaround listed…
I know you mention
bigintin your question title, but the question body talks about the number being too big to create the array – I suspect there are plenty of numbers which are small enough forxrangeto work, but big enough to cause you memory headaches withrange.