Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code that extracts information from the data structure #46

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nikoSchoinas
Copy link

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

More specifically the information is:

  • the maximum age of people in the group
  • the average (mean) number of relations among members of the group
  • the maximum age of people in the group that have at least one relation
  • the maximum age of people in the group that have at least one friend

@nikoSchoinas nikoSchoinas changed the title Add code that extracts information from the data stracture Add code that extracts information from the data structure Oct 23, 2020
Comment on lines +52 to +66
group_ages = [value['age'] for value in my_group.values()]
print("the maximum age of people in the group is:", max(group_ages))

# Block of code that calculates the average of connections
# Follow quite similar approach as before with the difference that now we need the average
group_connections = [len(value['relations']) for value in my_group.values()]
print("Every person in the group has an average of", sum(group_connections)/len(group_connections),"relations")

# Block of code that extracts the maximum age in the group
group_ages = [value['age'] for value in my_group.values() if len(value['relations']) > 0]
print("the maximum age of people in the group that have at least one relation is :", max(group_ages))

my_group =
# Block of code that extracts the maximum age of people in the group that have at least one friend
group_ages = [value['age'] for value in my_group.values() for relation_value in value['relations'] if relation_value['type'] == Relation.FRIEND]
print("the maximum age of people in the group that have at least one relation is :", max(group_ages))
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants