It does everything!
>>> def insert_spaces(text, s_range): return ' '.join(text[start:end] for start, end in zip([0] + s_range, s_range + [len(text)])).strip()
Example question:
>>> insert_spaces('Hello how are you today Joe', range(0, 27, 2)) 'He ll o ho w ar e yo u to da y Jo e'
Other examples with different starts , steps and stops :
>>> insert_spaces('Hello how are you today Joe', range(5, 20, 4)) 'Hello how are you today Joe' >>> insert_spaces('Hello how are you today Joe', range(0, 27)) 'H ellohowareyoutoday J oe' >>> insert_spaces('abcdefghijklmnopqrstuvwxyz', range(0, 16, 5)) 'abcde fghij klmno pqrstuvwxyz'
jamylak
source share