2
I’m trying to write a python script that takes n keywords and a number as input. This number will be my maximum range of string that will be written to the Wordlist.
1° Problem: As many combinations as possible have to be made between these input strings, without losing any possible combination or string in the middle of the path;
2nd Problem: If you exceed the range defined in the input, the string cannot be cut, simply the word that does not fit into the default "space" is outside the string of the process in question, but words left out also need to go through the process of having as many combinations as possible with all other words.
My code has some screen outputs because I am debugging but the idea is that the output at the end goes to a text file.
I’m almost there, but the strings still come out with a letter or two that shouldn’t.
My code is as follows (python 2.7):
import sys
import itertools
maxi = sys.argv[1]
if int(maxi) > 24:
print ">>For secure, the max of range of string was setup as 24<<"
print "Old value: " + maxi
maxi = 24
maxi = int(maxi)
words = sys.argv[2:]
wn = len(words)
print words
print "Inserted Words: " + str(len(words))
cw = 0
cutd = 0
nwords = []
tmp = ""
for word in itertools.imap(''.join, itertools.permutations(words, r=wn)):
if len(word) <= maxi:
nwords.append(word)
nwords = list(set(nwords))
cw = cw+1
#Permutations, slicing of the big ones
else:
word = word[:maxi]
for inp in words:
if word.find(inp) != -1: # if word has inp do, returning != == True:
tmp = word.replace(inp, "")
word = word.replace(tmp,"")
nwords.append(word)
nwords = list(set(nwords))
cutd = cutd+1
print nwords
print "\nWords Count: " + str(cw)
print "\nCutted Words Count: " + str(cutd)
print "\nFinal Words in list: " + str(len(nwords))
Hard to understand what is the purpose of the code. It has how to give an example of an input and what would be the expected output?
– Woss
Really hard to understand what the goal is, I tried to run this code in python3, several errors.
– Sidon
@Andersoncarloswoss How the Code should be working: Let’s say the input is: 8 "guy" "candle" "pineapple" "Berta" The output should be: caravel, velacara, pineapple, Berta OU input: 5 "Face" "candle" "pineapple" "Crossbow" Outlet: face, candle, Crossbow
– G Mattos
@Andersoncarloswoss The point is that itertools.product() makes all the possible combinations between strings, so what I thought was to take this string generated by the function and see if it fits the range that is the maxi variable, defined in the input, fits, goes to nwords[] list, if it doesn’t fit she goes through a treatment. First it is cut well in the position defined by the range with word = word[:maxi] then, and this is what is giving error, it should be checked in this string if when it is cut and there is a syllable or letter left of the string before the treatment
– G Mattos
@Sidon the code was written in 2.7, I forgot to tell you before
– G Mattos
@Gmattos but the
itertools.product
does not return a list? I did not understand this detail of remaining syllable.– Woss
@Andersoncarloswoss Yes but for every word generated by
itertools.product
and inserted in the list byif len(word) <= maxi:
that checks if the generated word is within the limit, if it is, goes untreated, if it is not, that’s where the problem lives. I cut the string according to the limitword = word[:maxi]
, after that, depending on the combination, one syllable or letter remains, the logic would be to check which complete words exist in this cut string, delete those words until you identify the rest, delete that rest of the string that will actually end up in the list.– G Mattos