0

Capital indexes

i am creating a function that find the index of capital letters in a string but this function instead of returning all the indexes of capital letters it return the index of the first capital letter and then it stops can any one help me with this? def capital_indexes(string): for index , char in enumerate(string): if char.isupper(): capital_indexes1 = [] capital_indexes1.append(index) return capital_indexes1 print(capital_indexes(input()))

29th Sep 2022, 12:50 PM
Mirwais Sherzad
2 odpowiedzi
+ 6
return [idx for idx, c in enumerate(string) if c.isupper()]
29th Sep 2022, 1:26 PM
Oma Falk
Oma Falk - avatar
+ 1
ok worked with this def capital_indexes(string): capital_indexes1 = [] for index , char in enumerate(string): if char.isupper(): capital_indexes1.append(index) return capital_indexes1
29th Sep 2022, 1:04 PM
Mirwais Sherzad