I have a large txt file whose structure looks like :
- title_topic --> ~1900 different values
- title_foreach_post --> can be the same with title_topic or []
- post_number --> starts from null and goes up to n
I was wondering if there is a way to a) regroup and sort all lines that have the same title_topic and b) sort them afterwards based on logical number order (1,2..9,10,11, 12 etc.).
Thank you all in advance.
Example of txt file :
{"title_topic": "Résoudre un problème avec Go voyage", "title_foreach_post": ["\nRe: Résoudre un problème avec Go voyage "], "post_number": "null"}
{"title_topic": "Résoudre un problème avec Go voyage", "title_foreach_post": ["\nRe: Résoudre un problème avec Go voyage "], "post_number": "1."}
{"title_topic": "Résoudre un problème avec Go voyage", "title_foreach_post": ["\nRe: Résoudre un problème avec Go voyage "], "post_number": "10."}
{"title_topic": "Loueur Goldcar ne rembourse pas une réservation annulée", "title_foreach_post": ["\nRe: Loueur Goldcar ne rembourse pas une réservation annulée "], "post_number": "null"}
{"title_topic": "Loueur Goldcar ne rembourse pas une réservation annulée", "title_foreach_post": ["\nRe: Loueur Goldcar ne rembourse pas une réservation annulée "], "post_number": "1."}
{"title_topic": "Loueur Goldcar ne rembourse pas une réservation annulée", "title_foreach_post": ["\nRe: Loueur Goldcar ne rembourse pas une réservation annulée "], "post_number": "12."}
{"title_topic": "Résoudre un problème avec Go voyage", "title_foreach_post": ["\nRe: Résoudre un problème avec Go voyage "], "post_number": "11."}
{"title_topic": "Résoudre un problème avec Go voyage", "title_foreach_post": ["\nRe: Résoudre un problème avec Go voyage "], "post_number": "12."}
Output example:

As you can see in code below I use sorted() built-in function to sort list of entries by two fields
(e['title_topic'], e['post_number']).Just for example I'm reading input file from text string using
io.StringIO()to model file input, in real life you'll use regular file reading.Try it online!
Output: