Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Custom Filter Exercise
def my_filter(function, iterable):
output = []
for item in iterable:
if function(item):
output.append(item)
return output
the_list = [('name1', 'Reed'), ('song1', "Don't Turn Around"), ('name2', 'Jonathan'), ('song2', "All That She Wants")]
result = my_filter(lambda x: x[0].startswith('name'), the_list)
print(result)
songs = my_filter(lambda x: x[0].startswith('song'), the_list)
print(songs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment