verb_color_map = {'likes': 'red', 'dislikes': 'blue', 'knows': 'black'}
with open('infile.txt') as infile:
    for line in infile:
        subject, verb, object_ = line.split()
print('%s -> %s %s;' % (subject, object_, verb_color_map[verb]))
Put bar at the end of every line that includes foo