+ 1
Help with this
This is a section of what I'm working on, it's about permutation, I want it to do something like this, for example, the user_input "cae" ["c","a","e","ca","ce","ac","ae"....], It's doing this instead ["cae","cea","ace","aec"...] https://code.sololearn.com/ck0UY018XC46/?ref=app
2 ответов
+ 2
import itertools
user_input = input() #no need to convert input to str since it is already a str
e = []
def x (str):
for i in range(1, len(user_input)+1):
x_lst = list(itertools.permutations(str, i)) #permutation's second argument -
#lenght of resulting tuples.
for word in x_lst:
d = (''.join(word))
e.append(d)
x(user_input)
print(e)
if input is 'cae' , we'll get:
['c', 'a', 'e', 'ca', 'ce', 'ac', 'ae', 'ec', 'ea', 'cae', 'cea', 'ace', 'aec', 'eca', 'eac']
0
strawdog thank you and I'll change that