May-06-2018, 04:26 AM
So I'm trying to solve this exercise: https://open.kattis.com/problems/cups
Although the problem is simple and does not require much work I'd like to improve my code because it looks pretty bad:
Although the problem is simple and does not require much work I'd like to improve my code because it looks pretty bad:
#!/usr/bin/python3 n = int(input()) a = [input().split() for i in range(n)] for i in a: if(i[0].isdigit()): i[0] = int(i[0])/2 i[1], i[0] = i[0], i[1] elif(i[1].isdigit()): i[1] = int(i[1]) a.sort(key=lambda x: x[1]) [print(i[0]) for i in a]The main concern is that I don't know if the string will be in a form int string or string int so I need to check for it.