how to sort file by numbers at end of txt | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to sort file by numbers at end of txt

i have two files that i have merged, but i need to sort them by years. in the text there is name, address, and birth year on each line. how do i sort using the years at the end of the sentences. i am using python.

25th Oct 2019, 2:33 AM
Kris
Kris - avatar
2 Answers
+ 2
Regular expressions and/or string slicing to get the years, then map year to line and sort by year. Or something like that.
25th Oct 2019, 2:35 AM
Rora
+ 2
1. read the files and save it into an array. you also need to separate the the name, address and birth year from the string into the array. 2. use the sorted function to sort the array. 3. print the result or update the files using the sorted arrays
25th Oct 2019, 2:37 AM
Shen Bapiro
Shen Bapiro - avatar