从完整的文本6集中过滤这些单词,其中第一个字母为大写,所有其他字母为小写。将结果存储在可变title_words中。打印title_words中存在的字数。
我面临着与以下链接相同的问题,
如何找到一个单词 - 第一个字母将是大写的,其他的会更低
挑战不接受任何答案。
2341 或 461 都不是。
试试这个!
title_words = []
for item in set(text6):
if item.istitle():
title_words.append(item)
print(len(title_words))
或者更蟒蛇:
title_words = [x for x in set(text6) if x.istitle()]
print(len(title_words))
对于更新,我们可以使用输入,但在在线编译器中它会抛出 eof erorr
定义检查(单词(: if(word[0].isupper((==True and word[1:len(word(].islower((==True(: 返回词 还: 返回假文本6=设置((text6.update(["word","App","jsk"](对于文本中的 i6:
print(check(i))
def check(word):
if(word[0].isupper()==True and word[1:len(word)].islower()==True):
return word
else:
return False
print(check("App"))