Skip to content

Instantly share code, notes, and snippets.

@reeddunkle
Last active May 5, 2016 16:50
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 reeddunkle/cd2bfb661fe1542681cc4f93a347937e to your computer and use it in GitHub Desktop.
Save reeddunkle/cd2bfb661fe1542681cc4f93a347937e to your computer and use it in GitHub Desktop.
Custom Map Exercise
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