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

Write group to file #70

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
32 changes: 30 additions & 2 deletions group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
"""An example of how to represent a group of acquaintances in Python."""
import yaml
"An example of how to represent a group of acquaintances in Python."""

# Your code to go here...

my_group =
my_group = {"Kyriazis":{"age":25,
"job":"Msc Student",
"relations":{"Mathew","Friend"}
},
"Mathew":{"age":24,
"job":"Phd Student",
"relations":{"Kyriazis":"Friend","Michael":"Friend"}
},
"Michael":{"age":25,
"job":"Phd Student",
"relations":{"Kyriazis":"Friend","Mathew":"Friend"}
},
"Emre":{"age":22,
"job":"Mres",
"relations":{"Kyriazis":"Friend","Mathew":"Friend","Michael":"Friend"}
}
}
print(f"All relations of Emre {my_group['Emre']['relations']}")

print(f"Relationship between Emre and Kyriazis {my_group['Emre']['relations']['Kyriazis']}")

with open('my_group.yaml', 'w') as yaml_group:
yaml_group.write(yaml.dump(my_group))

# makng sure the file can be read
with open('my_group.yaml') as yaml_group:
group_from_file = yaml.safe_load(yaml_group)
print(group_from_file)
25 changes: 25 additions & 0 deletions my_group.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Emre:
age: 22
job: Mres
relations:
Kyriazis: Friend
Mathew: Friend
Michael: Friend
Kyriazis:
age: 25
job: Msc Student
relations: !!set
Friend: null
Mathew: null
Mathew:
age: 24
job: Phd Student
relations:
Kyriazis: Friend
Michael: Friend
Michael:
age: 25
job: Phd Student
relations:
Kyriazis: Friend
Mathew: Friend