Skip to main content
1 of 3
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661

1 line, 180 bytes

exec("x={};"+"a=input('Enter subject: ')[:3].upper();b=int(input('Enter marks: '))\nif a not in x or x[a]<b:x[a]=b\n"*int(input("Enter number of tuples: "))+"print((*x.items(),))")

Attempt This Online!

3 lines, 171 bytes

x,i={},input
exec("a=i('Enter subject: ')[:3].upper();b=int(i('Enter marks: '))\nif a not in x or x[a]<b:x[a]=b\n"*int(i("Enter number of tuples: ")))
print((*x.items(),))

Attempt This Online!

Here's another approach that yields fewer bytes. It can be done in 1, 2 or 3 lines, with more lines enabling shorter overall programs. There's probably still even some improvements to be made here.

Wheat Wizard
  • 100k
  • 22
  • 282
  • 661