out = [next(it)]
for line in it:
    if ':' in line or not line:
        yield ' '.join(out)
out = []
out.append(line)
if out:
    yield ' '.join(out)
Python iterate over list and join lines without a special character to the previous item