「hello」などの重複した文字は含まれていないが、「helo」が含まれる単語だけを含むファイルから単語のリストを作成しようとしています。Pythonはファイルから単語のリストを作成します
単語を入力するだけで作成したリストを使用すると完全に自分のコードワードが表示されますが、ファイルリストでそれを実行しようとすると、重複する文字が含まれていてもすべての単語が印刷されます。
words = []
length = 5
file = open('dictionary.txt')
for word in file:
if len(word) == length+1:
words.insert(-1, word.rstrip('\n'))
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
x = 0
while x in range(0, len(alpha)):
i = 0
while i in range(0, len(words)):
if words[i].count(alpha[x]) > 1:
del(words[i])
i = i - 1
else:
i = i + 1
x = x + 1
print(words)
def has_double_letter(word):return len(word)!= len(set(word)) 'はどうですか? @KlausD。 –
私は可能な場合、それをシンプルに、任意のアイデアを保つために現在の方法を維持したいですか? – EllisR
次に、「動作しない」よりも優れたエラーの説明を与えます。 –