Python练习题答案: 查找首都【难度:1级】--景越Python编程实例训练营,1000道上机题等你来挑战

查找首都【难度:1级】:

答案1:

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

答案2:

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

答案3:

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

答案4:

def capitals(word):
    return [i for i, c in enumerate(word) if c.isupper()]
            
    #your code here​

答案5:

def capitals(word):
    return[i for (i,c) in enumerate(word) if  c.isupper()]#your code here​

答案6:

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

答案7:

string[i] for i in xrange(len(string))

答案8:

def capitals(word):
    uppers = []
    for i in range(len(word)):
        if word[i].isupper():
            uppers.append(i)
    return uppers​

答案9:

def capitals(word):
    #your code here
    uppers = []
    for i in range(len(word)):
        if(word[i].isupper()):
            uppers.append(i)
    return uppers
    ​

答案10:

def capitals(word):
    return [i for i in range(len(word)) if word[i].isupper()]

答案11:

def capitals(word):
    #your code here
    return [i for i in range(len(word)) if word[i].isupper() ]

答案12:

def capitals(word):
    return([i for i in range(len(word)) if word[i].isupper()])

答案13:

def capitals(word):
    return filter(lambda x: word[x].isupper(), range(len(word)))

答案14:

def capitals(word):
    return [index for index, char in enumerate(word) if str.isupper(char)]

答案15:

def capitals(word):
    word_array = list(word)
    index_array = []

    i = 0
    for letter in word_array:
        if (letter.isupper()):
            index_array.append(i)
        i += 1
    
    return index_array​

答案16:

def capitals(word):
    return [x for x in range(len(word)) if word[x].isupper()]

答案17:

def capitals(word):
    #your code here
    return [x for x in range(len(word)) if word[x].isupper()]

答案18:

capitals = lambda w: [i for i, e in enumerate(w) if e.isupper()]

答案19:

def capitals(word):
    #your code here
    a = []
    for i, j in enumerate(word):
        if j.upper() == j:
            a.append(i)
    return a
            
            ​

答案20:

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



Python基础训练营景越Python基础训练营QQ群

在这里插入图片描述
欢迎各位同学加群讨论,一起学习,共同成长!

版权声明:本文为aumtopsale原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/aumtopsale/article/details/101900860