Design
The keyword here is "stable sorting algorithm". Think of two stable sorting functions:
- one sorting according to length (maintaining the relative order of entries with equal lengths),
- the other sorting alphabetically.
In which order would you combine them in order to get the desired order?
Implementation
As others have mentioned, the first sorting function can be called like this:
list.sort(key=len, reverse=True)
The second sorting function can be called like this:
list.sort()
This should be enough to write a complete solution.
Result
If you combine the function in the right way, you should get the following:
>>> l = ['aaa', 'fff', 'bbb', 'ddd', 'e', 'cccc']
# ... sorting functions combined in the right way ...
>>> l
['cccc', 'aaa', 'bbb', 'ddd', 'fff', 'e']