-
Notifications
You must be signed in to change notification settings - Fork 64
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
nikoSchoinas
wants to merge
4
commits into
UCL-RITS:main
Choose a base branch
from
twemyss:nikoSchoinas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,66 @@ | ||
from enum import Enum | ||
|
||
"""An example of how to represent a group of acquaintances in Python.""" | ||
|
||
# Your code to go here... | ||
# Make a enum storing possible relation types and an ID for that relationship type | ||
class Relation(Enum): | ||
PARTNER = 1 | ||
FRIEND = 2 | ||
LANDLORD = 3 | ||
COUSIN = 4 | ||
|
||
|
||
# Store data as a dict of dict's, where the key is the ID of the user which is used in relations | ||
my_group = { | ||
1: { | ||
'name': 'Jill', | ||
'job': 'Biologist', | ||
'age': 26, | ||
'relations': [ | ||
{'to': 2, 'type': Relation.FRIEND}, | ||
{'to': 3, 'type': Relation.PARTNER} | ||
] | ||
}, | ||
2: { | ||
'name': 'Zalika', | ||
'job': 'Artist', | ||
'age': 28, | ||
'relations': [ | ||
{'to': 1, 'type': Relation.FRIEND} | ||
] | ||
}, | ||
3: { | ||
'name':'John', | ||
'job': 'Writer', | ||
'age': 27, | ||
'relations': [ | ||
{'to': 1, 'type': Relation.PARTNER} | ||
]}, | ||
4: { | ||
'name': 'Nash', | ||
'job': 'Chef', | ||
'age': 34, | ||
'relations': [ | ||
{'to': 3, 'type': Relation.COUSIN}, | ||
{'to': 2, 'type': Relation.LANDLORD} | ||
] | ||
}, | ||
} | ||
|
||
|
||
# Block of code that extracts the maximum age in the group | ||
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)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍