Last active
February 6, 2018 22:56
-
-
Save fabiocerqueira/66ece5d16186519299ba326082001fc9 to your computer and use it in GitHub Desktop.
example how map works(python3)
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
| class mymap: | |
| def __init__(self, func, seq): | |
| self.func = func | |
| self.seq = iter(seq) | |
| def __iter__(self): | |
| return self | |
| def __next__(self): | |
| return self.func(next(self.seq)) | |
| def mymap2(func, seq): | |
| for e in seq: | |
| yield func(e) | |
| if __name__ == '__main__': | |
| for i in mymap(lambda x: x*2, range(10)): | |
| print(i) | |
| for i in mymap2(lambda x: x*2, range(10)): | |
| print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment