Need help with sorting numbers

How can i create a script that automatically sorts the first numbers but keeps the last two 0s or 1s
Example:

Input:
A: 105 1 0
B: 568 1 1
C: 94 0 1

Desired output:
C: 94 0 1
A: 105 1 0
B: 568 1 1
The 1s and 0s should still stick to the original number that they were assigned to.

Thanks! :grinning:

That depends on the format you have them in and how you want to store them. If it’s just a string, you could split on whitespace and sort on the second field cast to an integer. If they’re already in a dictionary or a tuple you’d do something else.

inputstring = """A: 105 1 0
B: 568 1 1
C: 94 0 1"""

items = inputstring.splitlines()

items.sort(key=lambda x: int(x.split()[1]))
print("\n".join(items))```