PYTHON: QUESTION 7. The following function, in file block.py, is supposed to tak
ID: 3678336 • Letter: P
Question
PYTHON:
QUESTION 7. The following function, in file block.py, is supposed to take a string as argument and return a string that blocks the text in groups of 2. Eg block ('hello world') should return he llow or Id'. Unfortunately, this function does not work as advertised Please fix it and add types for all variables used in the function. In the comments section of your code, list the changes that you have made. def block (text): text string, output: string take text and block letters in groups of 2 text replace( btext ct 0 for letter in text: ct 1 btext else btext etter return btextExplanation / Answer
from itertools import tee, izip, islice >>> chunksize = 2 >>> s = 'hello world' >>> t = tee(s, chunksize) >>> for i, j in enumerate(t): ... next(islice(j, i, i), None) ... >>> ["".join(k) for k in izip(*t)]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.