I’m messing around and learning Python for the first time.
I know this is not a realistic project but please bear with me.
So basically this code takes a wordlist and permutatates it “N” number of times, and then writes the output into a “powerset.txt” file.
My question is how could I prevent the generation* of numbers that aren’t let’s say Length=4 example-> (0,0,0,0) or (3,0,2,1)
*I don’t wish to clean the list after they are already created.
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 ("do you work 2:", wordlist_abs_file_path,"\n") #test with open(wordlist_abs_file_path) as wordlist: for line in wordlist: word_list.append(line.rstrip()) # GENERATE POWERSET powerset_list =  print ("do you work 3:") #test 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() print("ok")