Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Adding changes that print out the requested values#61

Open
i-gayo wants to merge 8 commits intoUCL-RITS:mainfrom
swishswish123:Iani
Open

Adding changes that print out the requested values#61
i-gayo wants to merge 8 commits intoUCL-RITS:mainfrom
swishswish123:Iani

Conversation

@i-gayo
Copy link

@i-gayo i-gayo commented Oct 27, 2020

Adding changes that print out max age of groups

Answers UCL-RITS/rse-classwork-2020#10

@i-gayo i-gayo changed the title Iani Adding changes that print out the requested values Oct 27, 2020
@stefpiatek
Copy link
Collaborator

Thanks for your solution - can you do it using a comprehension expression?
So using the example solution for the first part it would be:

print(max(person["age"] for person in group.values()))  
# 34

# 2. Average (mean) number of relations among members of the group
no_relations = []
[no_relations.append(len(member['relations'])) for member_name, member in group.items()]
no_relations = [len(member['relations']) for member_name, member in group.items()]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, you could also make a function that calculates the mean from a list and use that on the output of the list

def mean(data):
    """Compute the average of a non-empty list of numbers."""
    return sum(data) / len(data)

mean([len(person["relations"]) for person in group.values()])  # 1.5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants