Skip to content

Latest commit

 

History

History
54 lines (33 loc) · 756 Bytes

Find_the_capitals.md

File metadata and controls

54 lines (33 loc) · 756 Bytes

CodeWars Python Solutions


Find the capitals

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] );

Given Code

def capitals(word):
    pass

Solution 1

def capitals(word):
    inds = []
    i = 0
    for l in word:
        if l.isupper():
            inds.append(i)
        i += 1
    return inds

Solution 2

def capitals(word):
    return [i for (i, c) in enumerate(word) if c.isupper()]

See on CodeWars.com