Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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)
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