Skip to content

Instantly share code, notes, and snippets.

@reeddunkle
Created May 2, 2016 18:59
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/569b6eb11340292be398faa5c431ac6d to your computer and use it in GitHub Desktop.
Save reeddunkle/569b6eb11340292be398faa5c431ac6d to your computer and use it in GitHub Desktop.
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