Advertisement
here2share

# split_combos.py

Dec 31st, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. # split_combos.py
  2.  
  3. import itertools
  4.  
  5. sentence = "this is just a test"
  6. words = sentence.split()
  7.  
  8. splits = []
  9. for i in range(1, len(words)):
  10.     for indices in itertools.combinations(range(1, len(words)), i):
  11.         split = [words[i:j] for i, j in zip((0, *indices), (*indices, len(words)))]
  12.         splits.append(split)
  13.  
  14. for split in splits:
  15.     print(split)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement