Python. file in, two files out, sorting by key and value of a dictionary. Read from a file input.txt: a number and a name each on a line (the file could be of any number of lines, here is 6 as an example below) 4 Cows 5 Camels 1 Peacock 3 Whales 4 Lions 2 Scorpions create two output files: first output_file1.txt : sort by (dictionary) key but those sharing the same key should be listed on the same line with ; separation 1: Peacock 2: Scorpions 3: Whales 4: Cows; lions ------------------------------> separated by ';' because they share the same key 4 5: Camels second output_file2.txt: Only values of the dictionary are sorted as follows and written to file: Camels Cows Lions Peacock Scorpions Whales
Python. file in, two files out, sorting by key and value of a dictionary.
Read from a file input.txt:
a number and a name each on a line (the file could be of any number of lines, here is 6 as an example below)
4
Cows
5
Camels
1
Peacock
3
Whales
4
Lions
2
Scorpions
create two output files:
first output_file1.txt : sort by (dictionary) key but those sharing the same key should be listed on the same line with ; separation
1: Peacock
2: Scorpions
3: Whales
4: Cows; lions ------------------------------> separated by ';' because they share the same key 4
5: Camels
second output_file2.txt:
Only values of the dictionary are sorted as follows and written to file:
Camels
Cows
Lions
Peacock
Scorpions
Whales
Thank you
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)