actually, the easiest way would be to add sorted to your line 5 list comprehension
a = [sorted(input().split()) for i in range(n)]this way you always get the number as element with index 0 because when sorting '0' to '9' always go before 'A'
def parse_data(item): return (int(item[0]), item[1]) data = ['red 10', '10 blue', 'green 7'] data = [parse_data(sorted(item.split())) for item in data] output = [cup for radius, cup in sorted(data)] print('\n'.join(output))note that sample output in your assignment is NOT correct
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs