I have the code:
marks = tuple(tuple((input("Enter subject: "), input("Enter marks: "))) for _ in range(int(input("Enter number of tuples: "))))
print(tuple((s[:3].upper(), max(int(m) for t, m in marks if t == s)) for s in set(t for t, m in marks)))
#INPUT
(("Physics",131),("Chemistry",30),("Physics",100),("Computers",50),("Chemistry",20))
#OUTPUT
(('COM', 50), ('PHY', 131), ('CHE', 30))
As you can see, the output is a nested tuple of the first three capitalized letters of the subject and the maximum mark given for each subject.
You can assume that Physics, Chemistry and Computers are the only subjects that the user inputs, and that they always use the same spelling for the subjects.
The order of the subjects in the output does not matter.
Is there anyway I can do the same without using the max function? The length of the code should optimally be at 2 lines or if at all possible, a single line. The maximum limit of the number of lines of code is 3.
The solution should try to contain no built in functions if possible. Functions like sort(), sorted() and max() are strictly not allowed.
tuple(x)
with(*x,)
to save some bytes \$\endgroup\$