Last active
April 10, 2020 19:24
-
-
Save narendranathjoshi/d2ce4751b1f3266e17ad5eda09efed28 to your computer and use it in GitHub Desktop.
Print every nth element when iterating over large lists - Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iterctr(items, n): | |
ctr = 0 | |
for item in items: | |
ctr += 1 | |
if ctr % n == 0: | |
print(ctr) | |
yield item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment