Jan-30-2018, 09:05 AM
I have seen this sample code from one python book:
def lines(file): for line in file: yield line yield '\n' def blocks(file): block = [] for line in lines(file): if line.strip(): block.append(line) elif block: yield ''.join(block).strip() block = []I am not sure what does "yield '\n'" do in line 3. I am also not sure when these two conditions: "if line.strip()" and "elif block" will be triggered. I am pretty new in python. Hope you guys can help me understand this code more. thanks!