-
-
Save stefpiatek/876e486a22f71341c944fa6cc66adee2 to your computer and use it in GitHub Desktop.
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
# example data structure solution | |
group = { | |
"Jill": { | |
"age": 26, | |
"job": "biologist", | |
"relations": { | |
"Zalika": "friend", | |
"John": "partner" | |
} | |
} | |
,"Zalika": { | |
"age": 28, | |
"job": "artist", | |
"relations": { | |
"Jill": "friend" | |
} | |
} | |
, | |
"John": { | |
"age": 27, | |
"job": "writer", | |
"relations": { | |
"Jill": "partner" | |
} | |
}, | |
"Nash": { | |
"age": 34, | |
"job": "chef", | |
"relations": { | |
"John": "cousin", | |
"Zalika": "landlord" | |
} | |
} | |
} | |
# Not strictly needed | |
def mean(data): | |
"""Compute the mean of a non-empty list of numbers.""" | |
return sum(data) / len(data) | |
print(max(person["age"] for person in group.values())) # 34 | |
print(mean([len(person["relations"]) for person in group.values()])) # 1.5 | |
print(max(person["age"] for person in group.values() if person["relations"])) # 34 | |
print(max(person["age"] for person in group.values() if "friend" in person["relations"].values())) # 28 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment