Skip to content

Instantly share code, notes, and snippets.

@Drvanon
Created April 13, 2019 19:40
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 Drvanon/6a5b422f1cfc549d138d675bdbb0f2c1 to your computer and use it in GitHub Desktop.
Save Drvanon/6a5b422f1cfc549d138d675bdbb0f2c1 to your computer and use it in GitHub Desktop.
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