Hey everyone. For my project i need to extract single characters from a given string which are separated from each other by the increasing number of places. Each extracted character must be exactly one place more apart from its predecessor than the one before. We need to use a string formed from the extracted characters as an input for the next phase of the project.
Example1:
I now need to have a single class with two methods: 'shrink' and 'expand'.
Implement a class whose method 'shrink' matches the function you created for the extracting of characters.
The method 'expand' should place all the characters in their original positions, filling the space between each character with the 'space' character and return the result as a string.
Example1:
Example1:
Output:Input string: "OTORHINOLARYNGOLOGY".
Outring: "OTRNRL".
Example2:Output:Input string: "A clown has a red nose.".
Output string: "A lnsee".
This is the code i have for it now:def index_gen(end): current = 0 step = 1 while current < end: yield current current += step step += 1 def task(text): return "".join(text[idx] for idx in index_gen(len(text))) if __name__ == "__main__": text = "A clown has a red nose." print(text) print(task(text)) return chars_extractedI need to upgrade this code with this:
I now need to have a single class with two methods: 'shrink' and 'expand'.
Implement a class whose method 'shrink' matches the function you created for the extracting of characters.
The method 'expand' should place all the characters in their original positions, filling the space between each character with the 'space' character and return the result as a string.
Example1:
Output:Input string: "OTRNRL".
Output string: "OT R N R L".
Example2:Output:Input string: "A lnsee".
Output string: "A l n s e e".
Anyone knows how to do this, im not as proficient to do this.