I want to get combinations of substrings like an example below:
- original string: “This is my pen”
- expected output list: [“This is my pen”, “This is mypen”, “This ismy pen”, “Thisis my pen”, “This ismypen”, “Thisismy pen”, “Thisismypen”]
As you can see in the example, I’d like to get all substring combinations by removing a white space character(s) while keeping the order of the sequence.
I’ve tried to use strip(idx)
function and from itertools import combinations
. But it was hard to keep the order of the original sentence and also get all possible cases at the same time.
Any basic ideas will be welcomed! Thank you very much.
- I’m a newbie to programming so please let me know if I need to write more details. Thanks a lot.