我想用单词=“ WElCMMerC”写屏幕大写字母和索引号。例如[[0,W),(1,E),(3,C),(4,M),(5,M)。 ..]
def cap(word):
w=list(enumerate(i) for i in word if i!=i.lower())
print (w)
print(cap("WElCMMerC"))
我想用单词=“ WElCMMerC”写屏幕大写字母和索引号。例如[[0,W),(1,E),(3,C),(4,M),(5,M)。 ..]
def cap(word):
w=list(enumerate(i) for i in word if i!=i.lower())
print (w)
print(cap("WElCMMerC"))
You can loop over the result of
enumerate
, and keep only those which have an uppercase letter (usingisupper
to check for that), and return the listw
, don't print inside the function:输出: