How do I get the index of all lower case letters of a string?
For example, the string "AbCd"
would lead to [1,3]
.
A simple iteration over the string would do it:
s = "AbCd"
result = []
for i, a in enumerate(s):
if a.islower():
result.append(i)
Another way would be a list comprehension:
s = "AbCd"
result = [i for i, a in enumerate(s) if a.islower()]
Both cases result in the same:
result = [1,3]