1student_data = {'id1':
2 {'name': ['Sara'],
3 'class': ['V'],
4 'subject_integration': ['english, math, science']
5 },
6 'id2':
7 {'name': ['David'],
8 'class': ['V'],
9 'subject_integration': ['english, math, science']
10 },
11 'id3':
12 {'name': ['Sara'],
13 'class': ['V'],
14 'subject_integration': ['english, math, science']
15 },
16 'id4':
17 {'name': ['Surya'],
18 'class': ['V'],
19 'subject_integration': ['english, math, science']
20 },
21}
22
23result = {}
24
25for key,value in student_data.items():
26 if value not in result.values():
27 result[key] = value
28
29print(result)
30
31
1
2# ----- Create a list with no repeating elements ------ #
3
4mylist = [67, 7, 89, 7, 2, 7]
5newlist = []
6
7 for i in mylist:
8 if i not in newlist:
9 newlist.append(i)
10
1# set the dict to a tuple for hashability, then use {} for set literal and retrn each item to dict.
2[dict(t) for t in {tuple(d.items()) for d in l}]
3# using two maps()
4list(map(lambda t: dict(t), set(list(map(lambda d: tuple(d.items()), l)))))
1import itertools
2mylist = [{'x':2020 , 'y':20},{'x':2020 , 'y':30},{'x':2021 , 'y':10},{'x':2021 , 'y':5}]
3mylist1=[]
4for key, group in itertools.groupby(mylist,lambda x:x["x"]):
5 max_y=0
6 for thing in group:
7 max_y=max(max_y,thing["y"])
8 mylist1.append({"x":key,"y":max_y})
9print(mylist1)
10