Last active
May 5, 2016 16:50
-
-
Save reeddunkle/cd2bfb661fe1542681cc4f93a347937e to your computer and use it in GitHub Desktop.
Custom Map Exercise
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
NUMBERS = range(4) | |
NAMES = ['Rebecca', 'Georgi', 'Reed', 'Thom Yorke'] | |
def my_map(function, iterable): | |
output = [] | |
for element in iterable: | |
result = function(element) | |
output.append(result) | |
return output | |
results = my_map(lambda x: (x, NAMES[x]), NUMBERS) | |
# ------ | |
# If you make a separate method: | |
def numbers_to_tuples(x): | |
output = (x, NAMES[x]) | |
return output | |
results2 = my_map(numbers_to_tuples, NUMBERS) | |
print results | |
print '-' * 10 | |
print results2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment