簡體   English   中英

如何查找單詞 - 第一個字母大寫,其他字母小寫

[英]How to find a words - First letter will be capital & other will be lower

從完整的 text6 集中過濾這些單詞,第一個字母大寫,所有其他字母小寫。 將結果存儲在變量 title_words 中。 打印 title_words 中存在的單詞數。

我面臨與以下鏈接相同的問題,

如何找到一個單詞 - 第一個字母大寫,其他字母小寫

挑戰中不接受任何答案。

既不是 2341 也不是 461。

嘗試這個!

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))
def check(word): if(word[0].isupper()==True and word[1:len(word)].islower()==True): return word else: return False print(check("App"))

對於更新,我們可以使用輸入,但在在線編譯器中它會拋出 eof 錯誤

def check(word): if(word[0].isupper()==True and word[1:len(word)].islower()==True): return word else: return False text6=set() text6 .update(["word","App","Jsk"]) for i in text6:

print(check(i))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM