Answers for "does dictionary allow duplicates in python"

2

switching keys and values in a dictionary in python [duplicate]

my_dict = {2:3, 5:6, 8:9}

new_dict = {}
for k, v in my_dict.items():
    new_dict[v] = k
Posted by: Guest on February-16-2020
0

python dict remove duplicates where name are not the same

import itertools
mylist = [{'x':2020 , 'y':20},{'x':2020 , 'y':30},{'x':2021 , 'y':10},{'x':2021 , 'y':5}]
mylist1=[]
for key, group in itertools.groupby(mylist,lambda x:x["x"]):
    max_y=0
    for thing in group:
        max_y=max(max_y,thing["y"])
    mylist1.append({"x":key,"y":max_y})
print(mylist1)
Posted by: Guest on September-16-2021

Code answers related to "does dictionary allow duplicates in python"

Python Answers by Framework

Browse Popular Code Answers by Language