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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -