for line in input_file:
    parts = line.strip().split()
if parts[0] in flags:
    line = line + ' ' + flags[parts[0]]
output_file.write(line + '\n')
add text in a file with python (without replacing it)