Created
December 7, 2019 21:18
-
-
Save gtback/57a57a9672a36f417bd86078e73adc30 to your computer and use it in GitHub Desktop.
Turnstyle
This file contains hidden or 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 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