如何查找单词-首字母大写,其他字母小写

时间:2019-07-23 03:46:02

标签: python python-3.x nltk

从完整的text6集合中过滤掉这些单词,首字母大写,所有其他字母小写。将结果存储在变量title_words中。打印出现在title_words中的单词数。

我面临与以下链接相同的问题,

How to find a word - First letter will be capital & other will be lower

挑战中没有答案。

2341或461。

3 个答案:

答案 0 :(得分:0)

尝试一下!

title_words = []
for item in set(text6):
    if item.istitle():
        title_words.append(item)
print(len(title_words))

或更多pythonic:

title_words = [x for x in set(text6) if x.istitle()]
print(len(title_words))

答案 1 :(得分:0)

def检查(字):    if(word [0] .isupper()== True和word [1:len(word)]。islower()== True):         返回字    其他:         返回False 打印(检查(“应用”))

答案 2 :(得分:0)

为了进行更新,我们可以使用输入,但是在在线编译器中,它会抛出eof erorr

def检查(字):    if(word [0] .isupper()== True和word [1:len(word)]。islower()== True):         返回字    其他:         返回False text6 = set() text6.update([[“ word”,“ App”,“ Jsk”]) 对于text6中的我:

print(check(i))