Skip to content

Instantly share code, notes, and snippets.

@stefpiatek
Created November 5, 2020 09:15
Show Gist options
  • Save stefpiatek/876e486a22f71341c944fa6cc66adee2 to your computer and use it in GitHub Desktop.
Save stefpiatek/876e486a22f71341c944fa6cc66adee2 to your computer and use it in GitHub Desktop.
# 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