On 2021-01-08 09:56, Umar Draz wrote:
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.

Iterate through the list of dicts.

If you've seen the client before, then set the appropriate value or values in the dict to ''.

You can use a set to remember which clients you've already seen.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to