#!/usr/local/bin/python keys = {} input = file('test') for line in input: key = line.split(' ', 1)[0] if key not in keys: keys[key] = 1 print line,