每天一习题,提升Python不是问题!!有更简洁的写法请评论告知我!
https://www.cnblogs.com/poloyy/category/1676599.html
写一个函数,该函数 参数为1个字符串,请分析并返回包含字符串中所有大写字母索引的有序列表。 比如 indexOfCaps("eDaBiT") ? [1, 3, 5] indexOfCaps("eQuINoX") ? [1, 3, 4, 6] indexOfCaps("determine") ? []
def indexOfCaps(strs): res = [] num = 0 for i in strs: if i.isupper(): res.append(num) num += 1 print(res) indexOfCaps("eDaBiT") indexOfCaps("eQuINoX") indexOfCaps("determine")
原文:https://www.cnblogs.com/poloyy/p/12541674.html