さて、以下は私の問題です:
このプログラムはファイルから読み込み、rstrip('\n') を使用せずにリストを作成しますが、これは私が意図的に行ったものです。そこから、リストを印刷し、並べ替え、再度印刷し、並べ替えられた新しいリストをテキスト ファイルに保存し、リストで値を検索できるようにします。
私が抱えている問題はこれです:
名前を検索すると、どのように入力しても、リストにないことがわかります。
コードは、変数のテスト方法を変更するまで機能しました。検索機能は次のとおりです。
def searchNames(nameList):
another = 'y'
while another.lower() == 'y':
search = input("What name are you looking for? (Use 'Lastname, Firstname', including comma: ")
if search in nameList:
print("The name was found at index", nameList.index(search), "in the list.")
another = input("Check another name? Y for yes, anything else for no: ")
else:
print("The name was not found in the list.")
another = input("Check another name? Y for yes, anything else for no: ")
完全なコードについては、http://pastebin.com/PMskBtzJ
テキストファイルの内容:http: //pastebin.com/dAhmnXfZ
アイデア?検索変数に ( + '\n') を追加しようとしたことに注意する必要があるように感じます