Repository navigation
Expand file tree
/
Copy pathdictionary.py
More file actions
194 lines (151 loc) · 4.05 KB
/
Copy pathdictionary.py
File metadata and controls
194 lines (151 loc) · 4.05 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#dict : mutable == > key value pair
"""d1={"phy":85, "maths" :98}
phy : 85 ==> 1 pair == > key phy value 85
maths :98 ==> 1 pair == > key maths value 98
print(d1)
print(type(d1))
print(len(d1))
"""
"""d2= {78 : 98 , "com" : 56}
print(d2)
print(type(d2))
"""
# d1 ={"phy" : 98 , "com" :74, "maths" : 23}
"""print(len(d1))
print(min(d1))
print(max(d1))
print(sorted(d1))
"""
#method :
# d1 ={"phy" : 98 , "com" :74, "maths" : 23,"s.s" :60}
"""d1.clear()
print(d1)"""
"""d2=d1.copy()
print(d2)
"""
#add in to dict :
"""
d1["bio"] =85
print(d1)
"""
# print(d1.get("phy"))
# print(d1.keys())
# print(d1.values())
# print(d1.items())
'''l1=["xena","raghav" , "manush"]
d2 =dict.fromkeys(l1,100)
print(d2)
'''
"""
d1.pop("phy")
print(d1)
"""
"""d1.popitem()
print(d1)"""
"""d1.update(d2)
print(d1)"""
"""
task : 1
ask user to enter the 5 student name and marks and store in to dict
output ={"ram" : 85 , "sita" : 25 , "manav" : 65}
"""
#task:
# ask user to enter 5 student name and marks in dict
# task: sort by values
'''d1={}
for i in range (3):
a= input("enter name of student :")
b= int(input("enter marks of student:"))
d1[a]=b
print(d1)
d2=sorted(d1.values())
d3={}
for i in d2:
for a ,b in d1.items():
if i==b:
d3.update({a : b})
print(d3)
'''
# task
# Make a Python program to count letters of the word: MISSISSIPPI.
# Your program should store them in a dictionary as: {"M":1, "I":4, "S":4, "P":2}.
# Next, generalize this program for any word entered by user.
# a="MISSISSIPPI"
'''a=input("enter a word:")
d1={}
for i in a:
d1[i]=a.count(i)
print(d1)
'''
#task:
# result = {'Science': [88, 89, 62, 95, 50], 'Language': [77, 78, 84, 80, 60], 'Computers': [93, 88, 79, 96, 70]}
# Expected Output: [{'Science': 88, 'Language': 77}, {'Science': 89, 'Language': 78}, {'Science': 62, 'Language': 84}, {'Science': 95, 'Language': 80}]
'''d1={'Science': [88, 89, 62, 95, 50], 'Language': [77, 78, 84, 80, 60], 'Computers': [93, 88, 79, 96, 70]}
'''
#task:
# Write a Python program to drop empty items from a given dictionary.
# Original Dictionary:
# {'c1': 'Red', 'c2': 'Green', 'c3': None}
# New Dictionary after dropping empty items:
# {'c1': 'Red', 'c2': 'Green'}
'''d1={'c1': 'Red', 'c2': 'Green', 'c3': None}
d2={}
for i , j in d1.items():
if j !=None:
d2.update({i:j})
print(d2)
'''
#task:
'''Write a Python program to filter a dictionary based on values.
Original Dictionary:
{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190}
Marks greater than 170:
{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}
'''
'''d1={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190}
d2={}
for i , j in d1.items():
if j > 170:
d2.update({i:j})
print(d2)
'''
#task:
'''Write a Python program to sort Counter by value.
Sample data : {'Math':81, 'Physics':83, 'Chemistry':87}
Expected data: [('Chemistry', 87), ('Physics', 83), ('Math', 81)]
'''
'''d1={'Math':81, 'Physics':83, 'Chemistry':87}
l1=[]
d2=sorted(d1.values())
d3={}
for k in d2:
for i , j in d1.items():
if k==j:
l1.append((i,j))
print(l1[::-1])'''
#task:
'''[('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
Grouping a sequence of key-value pairs into a dictionary of lists:
{'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}
'''
'''l1 = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
l2 = []
d1 = {}
for i,j in l1:
if i not in d1:
d1[i] =[]
d1[i].append(j)
print(d1)
'''
#task:
'''A Python Dictionary contains List as a value. Write a Python program to update the list values in the said dictionary.
Original Dictionary:
{'Math': [88, 89, 90], 'Physics': [92, 94, 89], 'Chemistry': [90, 87, 93]}
Update the list values of the said dictionary:
{'Math': [89, 90, 91], 'Physics': [90, 92, 87], 'Chemistry':[90,87,93]}
'''
'''d1={'Math': [88, 89, 90], 'Physics': [92, 94, 89], 'Chemistry': [90, 87, 93]}
d1['Math'] = [x + 1 for x in d1['Math']]
d1['Physics'] = [x - 2 for x in d1['Physics']]
print(d1)
'''