Remove duplicate values from dictionary without removing key

Umar Draz unix.co at gmail.com
Fri Jan 8 04:56:38 EST 2021


I want to replace duplicate values with empty "" in my dictionary. Here is
my original dictionary.

items = [
    {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100},
    {'client': 'xyz','name': "Abdelmadjid Tebboune", 'rating': 4.0,
'total': 100},
    {'client': 'xyz','name': "Alexander Lukashenko", 'rating': 3.1,
'total': 100},
    {'client': 'xyz', 'name': "Miguel Díaz-Canel", 'rating': 0.32,
'total': 100},
    {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150},
    {'client': 'udz', 'name': "Abdelmadjid Tebboune", 'rating': 4.0,
'total': 100},
    {'client': 'udz', 'name': "Alexander Lukashenko", 'rating': 3.1,
'total': 150},
    {'client': 'udz', 'name': "Miguel Díaz-Canel", 'rating': 0.32, 'total': 150}
]


Now I want to create another dict with like this

items = [
    {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100},
    {'client': '','name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''},
    {'client': '','name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''},
    {'client': '', 'name': "Miguel Díaz-Canel", 'rating': 0.32, 'total': ''},
    {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150},
    {'client': '', 'name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''},
    {'client': '', 'name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''},
    {'client': '', 'name': "Miguel Díaz-Canel", 'rating': 0.32, 'total': ''}
]


Would you please help me how I can do this? and if this is not the right
place to ask this question then please help me where I can ask this? I had
tried stackoverflow but that not worked.


More information about the Python-list mailing list