Here is a simple one-liner solution, using RE and min function
.
Here I use (abuse
?!) the fact that Python allows implicit convert of False and True to 0 and 1 - which makes writing conditional increments very easy.
PS While I applaud using meaningful names for variables (one-letter names must be made illegal - unless in one-liner code snippets
), I would suggest to use Pythonic naming conventions - see PEP-8
import re shortest = min(words, key=lambda w: len(re.findall('[A-Z]', w)))As a lambda function you may also use something similar to the way you counted lower case - with a little twist
sum(c.isupper() for c in w)which may be or may not be more efficient

Here I use (abuse

PS While I applaud using meaningful names for variables (one-letter names must be made illegal - unless in one-liner code snippets

Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.