To import and sort Python text files into a list

Asked 2 years ago, Updated 2 years ago, 112 views

Hong Gil-dong Computer 72

Yi Sun-shin Electronics 50

a heterogeneous computer 80

When the data in the file is like this,

The data structure is made of classes with names, departments, and credits You want to use insert sorting to sort by credit, department, or name.

How should I load the file and put my name, major, and credit?

Hong Gil-dong Computer 72 respectively
name1 Hong Gil-dong major1 computer grade172

I need to store data values like this and sort them out with the rest, but I don't know what to do...

python file-io list class insertion-sort

2022-09-21 16:16

1 Answers

1. Download and run Microsoft VS Code.

2. Start a new file with Ctrl+N.

3. Paste the contents of the text file you uploaded. It's going to be like this.

4.Add "name1","major1","grade1" to the top line.

5. Press Ctrl+H to display this in the upper right corner. .*Click and hold the icon.

6. Type \n{2,} in Find, \n in Replace, and press Ctrl+Alt+Enter to 'Find and replace all'. And then it's going to be roughly like this.

7. This time, type ^([ga-he]{2,4})([ga-he]+)(\d+)$ in Find, type "$1",$2",$3" in Replace, and then run a replacement. Then it's going to be like this.

8. If you press the word UTF-8 in the lower right corner, the search window will appear. Enter Korean and press Enter to change the encoding of this file to EUC-KR.

9. Press Ctrl+S to save this file. Please give Extension as No Extension and make sure to put .csv at the end of the file name. Like this.

10. If you open the file with Excel, the data you want will be displayed in Excel. You can make a table, filter it, sort it, draw statistics, and do whatever you want.

+ King Sejong's real name was Lee Do, not Lee Se-jong.


2022-09-21 16:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.