Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change iteration rate on itertools

I have this iteration count using iter tools:

for i in itertools.count(start=2**68):

And I want it to bump up an exponent every time (68,69,70,71,…). Is there support for this in itertools? I have looked at the step option on the itertools documentation, but don’t see any way to change by exponential type only float, integer.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is not a function specially made for that, but it’s very easy to make what you want from basic components:

for i in map(lambda i: 2**i, itertools.count(start=68)):

Incidentally, one of the comments says map(lambda...) is an antipattern, and should instead be replaced with generator expressions. Here is how to do in case you wonder.

for i in (2**i for i in itertools.count(start=68)):
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading