Something like
In [1]: d = {'banana': 3, 'orange': 5, 'apple': 5}
In [2]: sorted(d.items(), key=lambda x: (-x[1], x[0]))
Out[2]: [('apple', 5), ('orange', 5), ('banana', 3)]
More Related Contents:
- How to sort a list with two keys but one in reverse order?
- What arguments does Python sort() function have?
- Sorting list based on values from another list
- Sorting arrays in NumPy by column
- Dictionary: Get list of values for list of keys
- Scrapy Crawl URLs in Order
- Quicksort with Python
- How to add multiple values to a dictionary key in python?
- Sort tuples based on second parameter
- How does the key argument in python’s sorted function work?
- Sorting Python list based on the length of the string
- Python: sort function breaks in the presence of nan
- Sort multidimensional array based on 2nd element of the subarray
- Sorted Word frequency count using python
- Tk treeview column sort
- How does python compare functions?
- Simulating Key Press event using Python for Linux
- Python data structure sort list alphabetically
- How do you sort files numerically?
- How to calculate time difference by group using pandas?
- Python .sort() not working as expected
- How to sort a list of objects based on an attribute of the objects in descending order?
- sort eigenvalues and associated eigenvectors after using numpy.linalg.eig in python
- Custom sorting with Pandas
- How to sort a list of strings in reverse order without using reverse=True parameter?
- Sort list while pushing None values to the end
- How can I sort a list, according to where its elements appear in another list?
- Sort strings by the first N characters
- Multi Index Sorting in Pandas
- Sort array’s rows by another array in Python