-5

How do I get the index of all lower case letters of a string?

For example, the string "AbCd" would lead to [1,3].

user1251007
  • 15,891
  • 14
  • 50
  • 76

1 Answers1

2

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]
user1251007
  • 15,891
  • 14
  • 50
  • 76