【发布时间】:2022-01-24 12:11:29
【问题描述】:
def capital_indexes(word):
letters = []
capital_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
index_letters = []
# append letters in the word to a list
for letter in word:
letters.append(letter)
# go through the letters in the list letters
for i in letters:
# checks if the indexes in the list match with the indexes in the list 'capital_leters'
if i in capital_letters:
index_letters.append(word.index(i))
return index_letters
word_capital = capital_indexes('TEsT')
# this should return (0, 1, 3) but it keeps returning (0, 1, 0)
print(word_capital)
【问题讨论】:
-
不知何故,这个 leetcode 是今天的问题吗?