+ 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

13th Dec 2018, 6:01 PM
Joseph Ojo
Joseph Ojo - avatar
2 Answers
+ 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']​
13th Dec 2018, 6:12 PM
strawdog - avatar
strawdog thank you and I'll change that
13th Dec 2018, 6:24 PM
Joseph Ojo
Joseph Ojo - avatar