Possible Duplicate:
How might I remove duplicate lines from a file?
I have a file with duplicated records that I want to remove. This is what I have tried
import sys
for line in sys.stdin:
line = line.rstrip()
line = line.split()
idlist = []
if idlist == []:
idlist = line[1]
else:
idlist.append(line[1])
print line[0], idlist
#did not work
and this
for line in sys.stdin:
line = line.rstrip()
line = line.split()
lines_seen = set()
dup = line[1]
if dup not in lines_seen:
lines_seen = dup
else:
lines_seen.append(dup)
print line[0], lines_seen
sys.stdin.close()
#did not work either!
This is what the input looks like
BLE 1234
BLE 1223
LLE 3456
ELE 1223
BLE 4444
ELE 5555
BLE 4444
And this is what I want the output to look like
BLE 1234
BLE 1223
LLE 3456
BLE 4444
ELE 5555
Thanks! edg