To clarify the picture, if i have a string:
'pac'
I would want to get the list of every permutation of it, in this example:
['p', 'a', 'c', 'pa', 'pc', 'pac']
Just like i would type any of it in some search engine like the one on Ebay and it would pop up "pac" as a suggestion.
Code bellow is what i achieved thus far, but it's obviously not working as it should. 'Names' is just a list with multiple names, for instance: ['pac', 'greg', 'witch']
letters = {}
for name in names:
temp = []
letter = []
temp2 = []
for let in name:
let = let.lower()
temp.append(let)
letter.append(let)
for i in range(0, len(name)):
for j in range(1, len(name) - i):
print(i, j, end=' ')
to_add = letter[i] + temp[j]
print(to_add, temp2)
temp2.append(to_add)
letter.append(to_add)
temp = temp2
temp2 = []
letters[name] = letter
return letters
If there is built-in function feel free to share it with me, but that's not the core of the problem.