Say I have a list and it include words like "aa"
and "bb"
. How I will be able to cancel all those same letter words?
答案 0 :(得分:2)
Firstly, typo. CleasingTest
is missing an n
.
Here's what you were after anyways. filter
-ing out those values that have all the same letter.
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()))
Output
['abs', 'abraham', 'absent', 'abilities', 'aaron', 'ability', 'absorption', 'about', 'above', 'abc', 'aboriginal', 'abstracts', 'absence', 'aberdeen', 'abortion', 'absolutely', 'able', 'ab', 'abandoned', 'abstract', 'abroad', 'absolute']