-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_7.py
More file actions
83 lines (63 loc) · 1.3 KB
/
Copy pathtask_7.py
File metadata and controls
83 lines (63 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'''
Task 7: Flatten Nested JSON
Input Dataset
{
"user": {
"id": 1,
"profile": {
"name": "John",
"address": {
"city": "NY"
}
}
}
}
Requirements
Flatten keys using dot notation
Expected Output
{
"user.id": 1,
"user.profile.name": "John",
"user.profile.address.city": "NY"
}
'''
data = {
"user": {
"id": 1,
"profile": {
"name": "John",
"address": {
"city": "NY"
}
}
}
}
output = {}
new ={}
for x, obj in data.items():
# print(x)
# output[x]=""
# for y,obj in data.items():
# # print(y+':',obj[y])
# print()
# output[y] = obj
for z, obj in data[x].items():
print("----",z)
if type(data[x][z]) != dict:
output.update({x+'.'+z:obj})
if type(data[x][z]) != int:
print()
for y,obj in data[x][z].items():
print("00----",y)
if type(data[x][z][y]) != dict:
output.update({x+'.'+z+'.'+y:obj})
else:
for i in obj.keys():
print(i)
output.update({x+'.'+z+'.'+y+'.'+i:obj[i]})
# final_dict = output[0]
# print(data)
print(output)
# print(new)
# print(final_dict)
# print(output['user.profile'].items())