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

Editing group dict and writing main function to retrieve data #45

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

Editing group dict and writing main function to retrieve data #45

wants to merge 5 commits into from

Conversation

sophmrtn
Copy link

@sophmrtn sophmrtn commented Oct 23, 2020

This commit contains code to print answers based on data comprehension e.g. maximum age, conditionality statements and looping through data.

Answering to issue UCL-RITS/rse-classwork-2020#10

@sophmrtn
Copy link
Author

This code contains functions allowing for saving and loading from a yaml file.
Noticed that the loaded yaml is automatically put in alphabetical order (by key) despite unordered key in the parsed dictionary.

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

Comment on lines +30 to +47
data = group_dict.values()

# 1. Calculate maximum age in the group
maximum_age = max([x['age'] for x in data])
print('The maximum age in group_dict is :', maximum_age)

# 2. Average number of relations in the group
import numpy as np
av_connections = np.mean([len(x['connection']) for x in data])
print('The average number of connections in group_dict is :', av_connections)

#3. The maximum age of people with at least one relation
maximum_age = max([x['age'] for x in data if len(x['connection']) >= 1])
print('The maximum age of people in group_dict with at least one connection is :', maximum_age)

#4. The maximum age of people in the group that have at least one friend
maximum_age = max([x['age'] for x in data if len([connection for connection in x['connection'].values() if connection=='friend']) >=1 ])
print('The maximum age of people in group_dict with at least one friend is :', maximum_age)
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