2017-06-14 67 views
0

所以基本上我的問題是這樣的。比方說,我有一個值Python如何搜索給定輸入的所有permutatio列表?

l1st = ['dog', 'cat', 'bird', 'monkey'] 

的列表和我要求用戶輸入

input = raw_input('Please enter the word you wish to search for: ') 

這裏的大問題。比方說,人要尋找

dog 

,但它的類型作爲

Dog 

我不想程序給他,只是因爲他得到了資本錯的錯誤消息。我可以使用什麼方法進行list.index搜索以查找(如果不是確切的話)最接近的相似單詞?

+0

https://stackoverflow.com/questions/319426/how-do-i-do-a-case-insensitive-string-comparison-in-python – Dadep

回答

1

致電lower()降低案件。

list = map(str.lower, ['dog', 'cat', 'bird', 'monkey']) 

同樣,

input = raw_input('Please enter the word you wish to search for: ').lower() 
if input in list: 
    ... #do something here 
1

您可以通過轉動兩個到他們的小寫形式比較字符串。這裏是documentation。正如你在做搜索使用:

if input.lower() == item.lower(): 
    do_stuff()