[Solved] How do I sort a text file by three columns with a specific order to those columns in Python?


Your question is still ambiguous. Your example doesn’t have the first field Team_Name introduced in your header. So the index here is probably off by one, but I think you get the concept:

#read lines of text file and split into words
lines = [line.split() for line in open("test.txt", "r")]
#sort lines for different columns, numbers converted into integers to prevent lexicographical sorting
lines.sort(key = lambda x: (x[1], x[2], int(x[3])))
#writing the sorted list into another file
with open("new_test.txt", "w") as f:
    for item in lines:
        f.write(" ".join(item) + "\n")

1

solved How do I sort a text file by three columns with a specific order to those columns in Python?