Created
September 11, 2017 20:24
-
-
Save fisher6/b81c9253eeb5e052445cae72ac0e786f 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
# implemention for (each) loop in python as a function. | |
# Example: | |
# forr([1,2,3], print) | |
# is the same as | |
# for item in container: | |
# print(item) | |
def forr(cont, func): | |
""" forr(cont, func) == for x in cont: func(x) """ | |
iterator = iter(cont) # or iter.__cont__ | |
while True: | |
try: | |
func(next(iterator)) | |
except StopIteration: | |
break |
Author
fisher6
commented
Jan 18, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment