Friday, 15 February 2013

Python - how to count number of uppercase letters in a string that is in a list -



Python - how to count number of uppercase letters in a string that is in a list -

for example, if have list:

s = ["johnny , annie", "great job guys", "she , i"]

how can create python count number of uppercase letters in each element of list? example, python should homecoming 2, 1, 2.

this code far:

def poisci_pare(besedilo): x = [] seznam = [] t = re.split("[.]", besedilo) e in t: x = x + e.split() s in x: if s == s.capitalize() , not s.startswith('"'): seznam.append(s)

this function makes list separates sentences dots , filters out uppercase words in it, i've no thought how create count uppercase letters..

try this:

[sum([c.isupper() c in a]) in s]

for illustration output:

[2, 1, 2]

python string list count uppercase

No comments:

Post a Comment