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

Exercise for week3 #59

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

Exercise for week3 #59

wants to merge 4 commits into from

Conversation

LuweiCai123
Copy link

@LuweiCai123
Copy link
Author

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

Comment on lines +44 to +57
age_1 = {friend: person["age"] for friend, person in my_group.items()}
print("The maximum age in the group is:", max(age_1.values()))

#Question 2#
no_relations = {friend: len(my_group[friend]['connection']) for friend, person in my_group.items()}
print("The average (mean) number of relations among members of the group: is", sum([x for x in no_relations.values()])/len(no_relations))

#Question 3#
age_2 = {friend: person["age"] for friend, person in my_group.items() if len(my_group[friend]['connection'])>=1}
print("The maximum age of people in the group that have at least one relation is:", max(age_2.values()))

#Question 4#
age_3 = {friend: person["age"] for friend, person in my_group.items() if "friend" in my_group[friend]['connection'].values()}
print("The maximum age of people in the group that have at least one friend is:", max(age_3.values()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 might be easier to just create a list comprehension so you don't need to keep on calling .values() for the dict

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.

2 participants