csv - Remove duplicate keys (and their values) from a dictionary PYTHON -
i have kind of file in .csv format , want remove duplicates key , values.(values same!)
1: 'value' 2: 'value' 3: 'value' 1: 'value' 1: 'value' 4: 'value'
and want :
1: 'value' 2: 'value' 3: 'value' 4: 'value'
i wrote snippet don't know hoe delete duplicate keys.
import csv open('cuff2clean.csv', 'rb') csvfile: chekreader = csv.reader(csvfile, delimiter='\t') d={} lista=[] row in chekreader: d[row[0]]=row[1]
any suggestion? thanks!!!
you don't have to, python deletes them automatically joe r wrote in comment.
example:
>>> = {} >>> a[1] = "value" >>> a[2] = "value" >>> a[3] = "value" >>> a[1] = "value" >>> a[1] = "value" >>> a[4] = "value" >>> {1: 'value', 2: 'value', 3: 'value', 4: 'value'}
you need write in file.
real problem if you'd need have more same keys (use list in case).
Comments
Post a Comment