I am trying to use list comprehension to cycle through the letters in a word and get new combinations after removing one letter at a time.
E.g. say the input string is a word: 'bathe'
I would like to get the output in a list (preferably) with the following [athe, bthe, bahe, bate]
ie, making just one pass from left to right
---- this is the literal, but I need to accomplish this with list comprehension
word = "bathe"
newlist1 = [word[1::], (word[1:2] + word[-3:]), (word[:2] + word[-2:]), word[:3] + word[-1:] ]
print('sample 1', newlist1)
newlist2 = [(word[1:2] + word[-3:]), (word[1:2] + word[-3:]), (word[:2] + word[-2:]), word[:3] + word[-1:] ]
print('sample 2', newlist2)
I got through the first pass with this code, but am stuck now
x = [(word[:i] + word[-j:]) for i in range(1,4) for j in range(4,1, -1)]
The output I get is obviously not right, but (hopefully) is directionally there (when it comes to using list comprehensions)
['bathe', 'bthe', 'bhe', 'baathe', 'bathe', 'bahe', 'batathe', 'batthe', 'bathe']