Skip to content

Instantly share code, notes, and snippets.

@gtback
Created December 7, 2019 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtback/57a57a9672a36f417bd86078e73adc30 to your computer and use it in GitHub Desktop.
Save gtback/57a57a9672a36f417bd86078e73adc30 to your computer and use it in GitHub Desktop.
Turnstyle
def generator():
for x in range(10):
yield x
class Turnstyle:
def __init__(self):
self.counter = 0
def count(self, iterable):
for item in iterable:
self.counter += 1
yield item
def main():
l = generator()
z = (x for x in l if x != 5)
t = Turnstyle()
print(t.counter)
z = t.count(z)
print(t.counter)
print(list(z))
print(t.counter)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment