for line in sorted(open('file')):
    line = line.strip()
if prev is not None and not line.startswith(prev):
    print(prev)
prev = line
if prev is not None:
    pass
Removing duplicated lines from a txt file