1|Page
Programming Assignment Unit 7
By
Zin Myo Tun
Department of Computer Science, University of the People
CS-1101-01: Programming Fundamentals - AY2024-T2
Supervised By
Dr Vikas Thada
Instructor, Department of Computer Science
University of the People
January 12, 2024
Zin Myo Tun, C1839791
2|Page
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
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
and read the content and
parse every line in the
Zin Myo Tun, C1839791
4|Page
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
and read the content and
parse every line in the
content into a dictionary.
Using for loop to the
dictionary strings to write
Zin Myo Tun, C1839791
5|Page
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 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.
Zin Myo Tun, C1839791
6|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,
Zin Myo Tun, C1839791
7|Page
'male'], 'Eve': ['cat ', 9,
'female'], 'Florence': ['rabbit',
19, 'female'],
'Ian': ['rabbit', 10, 'male'],
'Peter': ['dog', 10, 'male'],
'Simon': ['cat', 9,
'male'], 'Aurthur': ['Cat', 15,
'male'], 'Sara': ['rabbit', 19,
'female'],
'Maria': ['dog', 10, 'female']}
The list from the text file
AFTER inverting:
{'dog': ['Alex', 'Earnest',
'Peter', 'Maria'], 9: ['Alex',
'Eve', 'Simon'],
Zin Myo Tun, C1839791
8|Page
'male': ['Alex', 'Dennis',
'Earnest', 'Ian', 'Peter',
'Simon', 'Aurthur'],
'rabbit': ['Beth', 'Christine',
'Florence', 'Ian', 'Sara'], 15:
['Beth',
'Christine', 'Aurthur'],
'female': ['Beth', 'Christine',
'Eve', 'Florence',
Output
The list from the text file
BEFORE inverting:
{'Alex': ['dog', 9, 'male'],
'Beth': ['rabbit', 15, 'female'],
'Christine':
Zin Myo Tun, C1839791
9|Page
['rabbit', 15, 'female'],
'Dennis': ['cat', 19, 'male'],
'Earnest': ['dog', 10,
'male'], 'Eve': ['cat ', 9,
'female'], 'Florence': ['rabbit',
19, 'female'],
'Ian': ['rabbit', 10, 'male'],
'Peter': ['dog', 10, 'male'],
'Simon': ['cat', 9,
'male'], 'Aurthur': ['Cat', 15,
'male'], 'Sara': ['rabbit', 19,
'female'],
'Maria': ['dog', 10, 'female']}
The list from the text file
AFTER inverting:
Zin Myo Tun, C1839791
10 | P a g e
{'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',
Output
The list from the text file
BEFORE inverting:
Zin Myo Tun, C1839791
11 | P a g e
{'Alex': ['dog', 9, 'male'],
'Beth': ['rabbit', 15, 'female'],
'Christine':
['rabbit', 15, 'female'],
'Dennis': ['cat', 19, 'male'],
'Earnest': ['dog', 10,
'male'], 'Eve': ['cat ', 9,
'female'], 'Florence': ['rabbit',
19, 'female'],
'Ian': ['rabbit', 10, 'male'],
'Peter': ['dog', 10, 'male'],
'Simon': ['cat', 9,
'male'], 'Aurthur': ['Cat', 15,
'male'], 'Sara': ['rabbit', 19,
'female'],
'Maria': ['dog', 10, 'female']}
Zin Myo Tun, C1839791
12 | P a g e
The list from the text file
AFTER inverting:
{'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',
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, 'male'], 'Eve': ['cat ', 9, 'female'], 'Florence': ['rabbit', 19,
'female'], 'Ian': ['rabbit', 10, 'male'], 'Peter': ['dog', 10, 'male'], 'Simon': ['cat', 9, 'male'], 'Aurthur':
['Cat', 15, 'male'], 'Sara': ['rabbit', 19, 'female'], 'Maria': ['dog', 10, 'female']}
The list from the text file AFTER inverting:
Zin Myo Tun, C1839791
13 | P a g e
{'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
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
I decided to first open the
text file in reading mode
Zin Myo Tun, C1839791
15 | P a g e
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
I decided to first open the
text file in reading mode
and read the content and
parse every line in the
Zin Myo Tun, C1839791
16 | P a g e
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
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
Zin Myo Tun, C1839791
17 | P a g e
the file and added three
other
items, then read and stored
the items of the inverted
dictionary to the file
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
Zin Myo Tun, C1839791
18 | P a g e
items, then read and stored
the items of the inverted
dictionary to the file
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
Zin Myo Tun, C1839791
19 | 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
Zin Myo Tun, C1839791