How do I sort a text file by three columns with a specific order to those columns in Python?
My text_file is in the following format with whitespaces between columns:
Team_Name Team_Mascot Team_Color Team_Hometown Number_of_Wins Team_Coach
Example:
Bears LittleBear Blue Beartown 15 BigBear
I want to sort it by Team_Color first, Team_Hometown second, and Number_of_Wins third in ascending order.
Therefore the attributes:
Bears Blue Beartown 15 Coach1
Bears Red Dogtown 30 Coach6
Bears Blue Cattown 15 Coach2
Bears Red Beartown 15 Coach4
Bears Blue Cattown 17 Coach3
Bears Red Dogtown 9 Coach5
My expected output is a sorted text file:
Bears Blue Beartown 15 Coach1
Bears Blue Cattown 15 Coach2
Bears Blue Cattown 17 Coach3
Bears Red Beartown 15 Coach4
Bears Red Dogtown 9 Coach5
Bears Red Dogtown 30 Coach6
I have thought about using lambda but none of my values are a tuple https://docs.python.org/3/tutorial/controlflow.html
I have looked at previous StackOverflow questions but most of them dealt with sorting two columns at maximum using lambda, tuple, or other methods