-
Notifications
You must be signed in to change notification settings - Fork 0
/
dict_parsing.py
148 lines (117 loc) · 2.58 KB
/
dict_parsing.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#DICT & LIST PROBLEMS (DICT_PARSING)
####Sort the list
l1 = [3, 1, 4, 2, 5]
l1.sort()
print(l1)
####print the squares of all the number in the list
l2 = [3, 1, 4, 2, 5]
for i in l2:
print(i*i)
####print all the elements in the list
l3 = [
(105, "d"),
(21, "z"),
(0, "v")
]
for x in l3:
for y in x:
print(y,end=" ")
####print the hex codes of all colors
####print the hex value of green
####Print all the value in the list
l = [
{
"color": "red",
"value": "#f00"
},
{
"color": "green",
"value": "#0f0"
},
{
"color": "blue",
"value": "#00f"
}
]
print()
print("Hex Codes of all Colours : ")
for i in l:
print(i["value"])
print()
print("Hex Codes of green Colour : ")
for i in l:
if i["color"]=="green":
print(i["value"])
print()
print("All Values in list : ")
for x in l:
for y in x:
a=y
print(x[y], end=" ")
####Print the languages that are inferior to Python
py = {'Python': 'Rocks', 'inferior': ['java', 'cobol']}
v1=py["inferior"]
for y in v1:
print(y)
####Print my Bill
prices = {'apple': 0.40, 'banana': 0.50}
my_purchase = {
'apple': 1,
'banana': 6}
x,y=0,0
for a in my_purchase:
for b in prices:
if a==b:
x=my_purchase[a]*prices[b]
y+=x
print("The price of", my_purchase[a], a, "is", x)
print("The total bill is", y)
####print the items
####print the roles
junk = {
"characters": {
"Lonestar": {
"id": 55923,
"role": "renegade",
"items": [
"space winnebago",
"leather jacket"
]
},
"Barfolomew": {
"id": 55924,
"role": "mawg",
"items": [
"peanut butter jar",
"waggy tail"
]
},
"Dark Helmet": {
"id": 99999,
"role": "Good is dumb",
"items": [
"Shwartz",
"helmet"
]
},
"Skroob": {
"id": 12345,
"role": "Spaceballs CEO",
"items": [
"luggage"
]
}
}
}
for x in junk:
for y in junk[x]:
for z in junk[x][y]:
print()
if z=="role":
print(z, "of", y, "is", junk[x][y][z])
elif z=="items":
print(z, "of", y, "is")
for i in junk[x][y][z]:
print(i, end=" ")
print()
print()