Created
April 13, 2019 19:40
-
-
Save Drvanon/6a5b422f1cfc549d138d675bdbb0f2c1 to your computer and use it in GitHub Desktop.
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 for_each(iterable, function): | |
running = True | |
while running: | |
try: | |
a = next(iterable) | |
function(a) | |
except StopIteration: | |
running = False | |
def length(array): | |
length = 0 | |
iterable = iter(array) | |
while array: | |
try: | |
next(iterable) | |
length += 1 | |
except StopIteration: | |
pass | |
return length | |
if __name__ == '__main__': | |
a = iter([1,2,3,4]) | |
for_each(a, print) | |
print(length(a) == len(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment