Professional Documents
Culture Documents
We then invert this dictionary in the same way as before, creating a new dictionary called
inv_dict. Finally, we open a new file called inverted_dict.txt in write mode using another with
statement, loop through the items in inv_dict, and write each key-value pair to the file in the
same format as our original input file.
To learn more about the setdefault() method used in the program, I referred to this Stack
Overflow post: https://stackoverflow.com/questions/3483520/use-cases-for-the-setdefault-
dict-method
For information on the split() method used to process lines in the input file, I used the Python
documentation: https://docs.python.org/3/library/stdtypes.html#str.split
To learn more about the join() method used to format the output file, I referred to this article
on Real Python: https://realpython.com/python-string-split-concatenate-join/