Last active
March 26, 2023 10:57
-
-
Save 1ort/96132fb19fea1134491eeffe13da852e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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