since you just want code it sounds like
from operator import itemgetter
sorted(map(itemgetter(1,-1),lists),key=itemgetter(-1))
heres some code that should do what you want … a teacher may want an explanation however… just fair warning
solved Python: Sorting and printing lists within lists [closed]