Use the Python List sort() method to sort a list in place. The sort() method sorts the string elements in alphabetical order and sorts the numeric elements from smallest to largest. Use the sort(reverse=True) to reverse the default sort order.
Problems associated with sorting and removal of duplicates is quite common in development domain and general coding as well.
Basically if given a list:
data = ["apple", "pear", "cherry", "apple", "pear", "apple", "banana"]
I'm trying to make a function that returns a list like this:
["apple", "pear", "banana", "cherry"]
I'm trying to make the return list ordered by most frequently occurring word first while breaking ties by ordering them alphabetically. I also am trying to eliminate duplicates.
I've made lists already of the counts of each element and the indices of each element in data.
x = [n.count() for n in data]
z = [n.index() for n in data]
I don't know where to go from this point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With