Feb-19-2024, 11:09 AM
I separated the task in two subtasks.
First Task: Generator to generate indices
Second Task: Join the text. The indices from the generator are used to get the characters.
First Task: Generator to generate indices
Second Task: Join the text. The indices from the generator are used to get the characters.
def index_gen(end): """ GeneratorFunction for indicies The generator yield numbers from 0 to < end. Example: >>> list(index_gen(20)) [0, 1, 3, 6, 10, 15] """ current = 0 step = 1 while current < end: yield current current += step step += 1 def task(text): """ >>> text = "A clown has a red nose." >>> task(text) 'A lnsee' """ return "".join(text[idx] for idx in index_gen(len(text))) if __name__ == "__main__": # Input string: "A clown has a red nose.". # Output string: "A lnsee". text = "A clown has a red nose." print(text) print(task(text))
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!