2016-12-02 5 views
-1

私はリストを持っており、それには"aa""bb"のような単語が含まれています。どのように私はそれらのすべての同じ文字の単語をキャンセルすることができるでしょうか?同じ文字のリストから単語を取り消すにはどうすればいいですか?

+2

タイプミス 'CleasingTest' =>' CleansingTest' –

+0

うーん... 'CleasingTest'が定義されていません。 –

+0

また、 'readWordList()'関数を呼び出すこともありませんでした。 'for i in readWordTest'はあなたが思うように動作しません –

答えて

2

まず、typo。 にはnがありません。

これはあなたが何とかしていたものです。 filter-すべての文字が同じ値を出力します。

from urllib.request import urlopen 

def not_all_letters_same(s): 
    return s != s[0]*len(s) 

response = urlopen("http://www.cs.queensu.ca/home/cords2/shortList.txt").read().decode('utf-8') 
words = list(filter(not_all_letters_same, response.split())) 

出力

['abs', 'abraham', 'absent', 'abilities', 'aaron', 'ability', 'absorption', 'about', 'above', 'abc', 'aboriginal', 'abstracts', 'absence', 'aberdeen', 'abortion', 'absolutely', 'able', 'ab', 'abandoned', 'abstract', 'abroad', 'absolute']

+0

thx男はちょうど輸入が正確に何をしたいのですか?そして私は本当にリターン部分を理解することができません。 –

+0

元のコードに 'import'があります。 return文については、http://stackoverflow.com/questions/14320909/efficiently-checking-that-string-consists-of-one-character-in-pythonを参照してください。 –

+0

大変ありがとうございます。ちょうど始まった。 –

関連する問題