Programming Assignment Unit 8 (1)
Programming Assignment Unit 8 (1)
By
Supervised By
Dr Vikas Thada
Instructor, Department of Computer Science
University of the People
Explanation
I decided to first open the
text file in reading mode
and read the content and
parse every line in the
content into a dictionary.
Using for loop to the
dictionary strings to write
the file and added three
other
items, then read and stored
the items of the inverted
dictionary to the file
Explanation
I decided to first open the
text file in reading mode
Zin Myo Tun, C1839791
3|Page
Output
The list from the text file
BEFORE inverting:
{'Alex': ['dog', 9, 'male'],
'Beth': ['rabbit', 15, 'female'],
'Christine':
['rabbit', 15, 'female'],
'Dennis': ['cat', 19, 'male'],
'Earnest': ['dog', 10,
{'dog': ['Alex', 'Earnest', 'Peter', 'Maria'], 9: ['Alex', 'Eve', 'Simon'], 'male': ['Alex', 'Dennis',
'Earnest', 'Ian', 'Peter', 'Simon', 'Aurthur'], 'rabbit': ['Beth', 'Christine', 'Florence', 'Ian', 'Sara'], 15:
['Beth', 'Christine', 'Aurthur'], 'female': ['Beth', 'Christine', 'Eve', 'Florence', 'Sara', 'Maria'], 'cat':
['Dennis', 'Simon'], 19: ['Dennis', 'Florence', 'Sara'], 10: ['Earnest', 'Ian', 'Peter', 'Maria'], 'cat ':
['Eve'], 'Cat': ['Aurthur']}
xplanation
I decided to first open the
text file in reading mode
and read the content and
parse every line in the
content into a dictionary.
Using for loop to the
dictionary strings to write
the file and added three
other
items, then read and stored
the items of the inverted
dictionary to the file
xplanation
Zin Myo Tun, C1839791
14 | P a g e
xplanation
I decided to first open the
text file in reading mode
and read the content and
parse every line in the
content into a dictionary.
Using for loop to the
dictionary strings to write
the file and added three
other
items, then read and stored
the items of the inverted
dictionary to the file