Last active
August 29, 2015 14:17
-
-
Save insanedefaults/f376000a22e5e429df38 to your computer and use it in GitHub Desktop.
Python Example
This file contains hidden or 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
# for asha | |
# This is a list of dictionaries, saved into people | |
people = [ | |
{ | |
'name' : 'tim', | |
'eyes' : 'brown', | |
'silly' : False | |
}, | |
{ | |
'name' : 'katy', | |
'eyes' : 'green', | |
'silly' : True | |
}, | |
{ | |
'name' : 'barry', | |
'eyes' : 'blue', | |
'silly' : False | |
} | |
] | |
# this is a function named blue_eyes(), it takes a list of dictionaries and returns a list of strings of names of people with blue eyes | |
def blue_eyes(list_of_people): | |
result = [] | |
for person in list_of_people: | |
if person['eyes'] == 'blue': | |
result.append(person['name']) | |
return result | |
# this for loop takes the list, returned from the blue_eyes function, and for each item in that list, says that they have blue eyes | |
for person in blue_eyes(people): | |
print(person + ' has blue eyes') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment