python - Copying a column without repeating -


i need access .txt file, has 2 columns , lot of rows repeated names (using python). want copy 1 of columns without repeating names on it, printing on new .txt file. tried:

g = open(file,'r') linesg = g.readlines() h = open(file,'w+') linesh = h.readlines() line in range(len(linesg)):      if linesg[line] in linesh:         line += 1      else:         h.write(linesg[line].split('\t')[1]) 

but continue have repeated names on .txt file. me? (yes, i'm newbie on python programming). lot!

g = open(file,'r') names = {} line in g.readlines():     name = line.split('\t')[1] #name in second tab     names[name] = 1 #create dictionary names  #names.keys() returns list of names here # change file handle here if needed, or original file overwritten.  h = open(file,'w+') name in names.keys():     h.write("%s\n"%name) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -