Skip to content

Instantly share code, notes, and snippets.

@narendranathjoshi
Last active April 10, 2020 19:24
Show Gist options
  • Save narendranathjoshi/d2ce4751b1f3266e17ad5eda09efed28 to your computer and use it in GitHub Desktop.
Save narendranathjoshi/d2ce4751b1f3266e17ad5eda09efed28 to your computer and use it in GitHub Desktop.
Print every nth element when iterating over large lists - Python 3
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