मैं इस स्क्रिप्ट को सूची से अधिकतम 3 संयोजन शब्दों की अनुमति देने के लिए कैसे बना सकता हूं?पायथन शब्दसूची क्रमपरिवर्तन
output > testpassword, passtestword, 10wordtest,....etc
:
pass
10
test
word
इसके बजाय संयोजन एक से चार शब्द यानी
output > pass10wordtest, 10testpassword,....etc
मैं अंतिम संयोजन होना चाहता हूँ सब से की
:
list.txt 4 तार के होते हैं
मेरा कोड:
from itertools import permutations
import os
# GET FILE
script_dir = os.path.dirname(os.path.realpath(__file__))
wordlist_rel_path = "List.txt"
wordlist_abs_file_path = os.path.join(script_dir, wordlist_rel_path)
# READ WORD LIST FROM FILE
word_list = []
print ("\ninput file is:", wordlist_abs_file_path,"\n")
with open(wordlist_abs_file_path) as wordlist:
for line in wordlist:
word_list.append(line.rstrip())
# PRINT INPUT LIST
print ("input list contains:")
print(word_list,"\n")
# GENERATE POWERSET
powerset_list = []
print ("output list is:")
for n in range(1, len(word_list)+1):
for perm in permutations(word_list, n):
powerset_list.append("".join(perm))
print(powerset_list)
# WRITE LIST TO FILE
powerset_rel_path = "powerset.txt"
powerset_abs_file_path = os.path.join(script_dir, powerset_rel_path)
powerset_abs_file = open(powerset_abs_file_path, 'w')
for item in powerset_list:
powerset_abs_file.write("%s\n" % item)
powerset_abs_file.close()
बढ़िया काम करता है! धन्यवाद! – sfad