Splitting a word into 2 in all possible ways in python -


how split word 2 in possible ways in python?

input - eg: stack

output - {s, tack},{st,ack},{sta, ck}, {stac,k}

i thought of writing loop there better way? can't think of method using itertools package. changes order of letters in word.

you can slice word index combination want

word = 'stack'     [ [word[:i],word[i:]] in range(1,len(word))]  [['s', 'tack'], ['st', 'ack'], ['sta', 'ck'], ['stac', 'k']] 

Comments