You use
Here how it look if write result to file.
close()
that's not needed when use with open
and there is no write()
.Here how it look if write result to file.
def line_concat(lst): temp = zip(lst[::2], lst[::-2]) return [':'.join(i) for i in temp] def file_read(file_in): with open(file_in) as f: lst = [line.strip() for line in f if not line.isspace()] return lst if __name__ == '__main__': file_in = 'xy.txt' lst = file_read(file_in) #print(lst) # Test file read with open('xy_new.txt', 'w') as f_out: for line in line_concat(lst): f_out.write(f'{line}\n')