I didn’t study last night. *sloth sloth sloth <echos>* I agree my bad. And I should keep moving forward without boring WordPress out with lists though. * sloth sloth sloth <keeps echoing in the background>*
So this is the last list problem which I’ll post. Practice list but post other things. But this question made me question myself.
# Write a Python program to get a list,
# sorted in increasing order by the last element
# in each tuple from a given list of non-empty tuples.
# Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
# Expected Result : [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
from operator import itemgetter
def sort (a):
return sorted(a, key=last)
return sorted(a, key=itemgetter(1), reverse=True)
a = [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
I learned about operator library, sorting, itemgetter. I’ll learn more.
Holla if you want me to set down explanations as well. Don’t holla. Just comment. *Thought to self: What am I?*