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.
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.
+ 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