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# 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)))))
1df.groupby(level=0).apply(lambda x: x.to_dict('r')).to_dict()
2# {'bob': [{'age': 20, 'name': 'bob'}, {'age': 30, 'name': 'bob'}],
3# 'jim': [{'age': 25, 'name': 'jim'}]}
4
1{k: g.to_dict(orient='records') for k, g in df.groupby(level=0)}
2# {'bob': [{'age': 20, 'name': 'bob'}, {'age': 30, 'name': 'bob'}],
3# 'jim': [{'age': 25, 'name': 'jim'}]}
4