Your tricky trick! However, I find it more convenient to read the lower characters, adding 1 for each.
def n_lower_chars(string): return sum(1 for c in string if c.islower())
In addition, we do not need to create a new list for this, so removing []
will cause sum()
to work on an iterator that consumes less memory.
source share