-
-
Save mjard/3137490 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
# pythonic | |
def map(source, func): | |
dest = [] | |
for x in source: | |
dest.append(func(x)) | |
return dest | |
# list comprehension | |
def map(source, func): | |
return [func(x) for x in source] | |
# lambda | |
map = lambda s,f: [f(x) for x in s] | |
# generator | |
def map(source, func): | |
for x in source: | |
yield func(x) | |
# desg | |
def map(list,func): | |
x = 0 | |
for len(list) in x: | |
new_list = new_list.append(func(list[x])) | |
x += 1 | |
return new_list | |
# desg that works | |
def map(source, func): | |
dest = list() # this is why we don't name things list | |
for i, x in enumerate(source): | |
dest.append(func(source[i])) | |
return dest | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment