How to sort a list of strings so that the number of capitals beginning the string is the main criterion?
What I have:
names = ["JOE", "Kate", "WILfried", "alfred", "denis"]
print sorted(names)
>>> ['JOE', 'Kate', 'WILfried', 'alfred', 'denis']
What I would like:
>>> ['JOE', 'WILfried', 'Kate', 'alfred', 'denis']
EDIT
In other words, I would like:
- in first positions, sorted strings beginning with n capitals
- then, sorted strings beginning with n-1 capitals
- " " " " " " " " " " " " " " " " " " " " " " " " " n-2 " " " " " "
- etc.
(Capitals following at least one lowercased character doesn't matter.)