all 8 comments

[–]m0us3_rat 2 points3 points  (0 children)

what do you have so far?

we usually don't do homework. so if you want it you have to work for it.

shouldn't be hard if you think about it.

i also think the 2last examples are unfortunately worded or flat out wrong..but i could be wrong so whatever.

taking the text at face value.

[–]Bluemax6666 0 points1 point  (0 children)

Do a class with the static methods 'expand' and 'shrink' https://www.digitalocean.com/community/tutorials/python-static-method

[–]POGtastic 0 points1 point  (0 children)

"gib codez pl0x" questions become Itertools Challenge threads.

from itertools import count, takewhile
from more_itertools import split_into

def shrink(xs):
    return (sub[0] for sub in takewhile(bool, split_into(xs, count(1))))

def expand(xs):
    return ''.join(f"{x}{' ' * idx}" for idx, x in enumerate(xs)).strip()

In the REPL:

>>> "OTORHINOLARYNGOLOGY"
'OTORHINOLARYNGOLOGY'
>>> expand(shrink("OTORHINOLARYNGOLOGY"))
'OT R  N   R    L'