반응형
Instructions
Write a function that takes a single string (word) as argument. The function must return an ordered list containing the indexes of all capital letters in the string.
Example
Test.assertSimilar( capitals('CodEWaRs'), [0,3,4,6] );
Solution:
1. Find the uppercase character in the string.
2. It returns the index of the corresponding character in an array.
def capitals(word):
return [i for i, v in enumerate(word) if v.isupper()]
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Sum of numbers from 0 to N (0) | 2022.05.11 |
---|---|
Round up to the next multiple of 5 (0) | 2022.05.10 |
Coding Meetup #5 - Higher-Order Functions Series - Prepare the count of languages (0) | 2022.05.08 |
Initialize my name (0) | 2022.05.07 |
Even numbers in an array (0) | 2022.05.06 |