Skip to content

Instantly share code, notes, and snippets.

@1ort
Last active March 26, 2023 10:57
Show Gist options
  • Save 1ort/96132fb19fea1134491eeffe13da852e to your computer and use it in GitHub Desktop.
Save 1ort/96132fb19fea1134491eeffe13da852e to your computer and use it in GitHub Desktop.
import itertools
from typing import Iterable
def apply_period(word: str, positions: Iterable[int]) -> str:
for index, position in enumerate(positions):
position += index
word = word[:position] + "." + word[position:]
return word
def get_periods(word: str, max_periods: int) -> Iterable[str]:
all_possible_periods = itertools.chain.from_iterable(
itertools.combinations(range(1, len(word)), periods)
for periods in range(1, max_periods + 1)
)
return (apply_period(word, periods) for periods in all_possible_periods)
for w in get_periods("helloworld", 3):
print(w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment