我有一個我正在開發的python字典制造商。我一直在拼湊,但我需要幫助。當我將它提交到一個文本文件或輸出時,它會在新文件之前重複單詞。例如,這可能是輸出一個時間: 一個 一個 一個 b 一個 ç如何刪除python輸出中的任何重複項
我需要的輸出爲 一個 b Ç
或(以幫助那些沒有得到它)的另一輸出的例子是: ABC CBA ABC CBA BCA
當它應該是: AAA AAB AAC ABA ABB ABC ACA ACB ACC 咩
等等。
任何人都可以幫助我嗎?這是我到目前爲止的代碼(將其保存到一個.txt名爲wordlist.txt文件)
import string, random
minimum=input('Please enter the minimum length of any give word to be generated: ')
maximum=input('Please enter the maximum length of any give word to be generated: ')
wmaximum=input('Please enter the max number of words to be generate in the dictionary: ')
alphabet =raw_input("What characters should we use to generate the random words?: ")
string=''
FILE = open("wordlist.txt","w")
for count in xrange(0,wmaximum):
for x in random.sample(alphabet,random.randint(minimum,maximum)):
string+=x
FILE.write(string+'\n')
string=''
print''
FILE.close()
print 'DONE!'
end=raw_input("Press Enter to exit")
你的問題不清楚。包括樣本輸入和樣本輸出。 – MYGz
['itertools.product'](https://docs.python.org/2/library/itertools.html#itertools.product)應該可以幫助你。 –