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