-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapital_indexes1.py
More file actions
35 lines (28 loc) · 904 Bytes
/
capital_indexes1.py
File metadata and controls
35 lines (28 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Challenge
# Capital indexes
# Write a function named capital_indexes.
#The function takes a single parameter, which is a string.
#Your function should return a list of all the indexes in
#the string that have capital letters.
# For example, calling capital_indexes("HeLlO") should
# return the list [0, 2, 4].
def capital_indexes(word):
cap_index = []
for i in word:
if i.isupper():
cap_index.append(word.index(i))
print(cap_index)
capital_indexes('HeLlO')
# # naive solution
# def capital_indexes(s):
# upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# result = []
# for i, l in enumerate(s):
# if l in upper:
# result.append(i)
# return result
# # shorter version
# from string import uppercase
# def capital_indexes(s):
# return [i for i in range(len(s)) if s[i] in uppercase]
# you can also use the .isupper() string method.