Skip to content

Commit 0b05466

Browse files
Add files via upload
1 parent 5767f7e commit 0b05466

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

Assignment-12.ipynb

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 7,
6+
"id": "90d93b46",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"['Akash', 'Borgalli', 'Laxman', 'Hanuman']\n"
14+
]
15+
}
16+
],
17+
"source": [
18+
"dict = {'107':'Akash','123':'Borgalli','897':'Akash','091':'Laxman','876':'Hanuman'}\n",
19+
"lst =[] \n",
20+
"for val in dict.values(): \n",
21+
" if val in lst: \n",
22+
" continue \n",
23+
" else:\n",
24+
" lst.append(val)\n",
25+
"print(lst)"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 8,
31+
"id": "035f7ac6",
32+
"metadata": {},
33+
"outputs": [
34+
{
35+
"name": "stdout",
36+
"output_type": "stream",
37+
"text": [
38+
"The sum of values is 43\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"dict = {'107':2,'123':3,'897':8,'091':10,'876':20}\n",
44+
"sum=0\n",
45+
"for val in dict.values():\n",
46+
" sum=sum+val\n",
47+
"print('The sum of values is',sum)\n"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": 10,
53+
"id": "42c4335f",
54+
"metadata": {},
55+
"outputs": [
56+
{
57+
"name": "stdout",
58+
"output_type": "stream",
59+
"text": [
60+
"{'107': 2, '123': 3, '897': 8, '091': 10, '876': 20}\n"
61+
]
62+
}
63+
],
64+
"source": [
65+
"dict = {'107':2,'123':3,'897':8}\n",
66+
"dict2={'091':10,'876':20}\n",
67+
"dict.update(dict2)\n",
68+
"print(dict)"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 25,
74+
"id": "9033743f",
75+
"metadata": {},
76+
"outputs": [
77+
{
78+
"name": "stdout",
79+
"output_type": "stream",
80+
"text": [
81+
"{'a': 'Apple', 'b': 'Ball', 'c': 'Cat'}\n"
82+
]
83+
}
84+
],
85+
"source": [
86+
"lst= [['a', 'Apple'], ['b', 'Ball'],['c', 'Cat'] ]\n",
87+
"dct={}\n",
88+
"for key,val in lst:\n",
89+
" dct[key]=val\n",
90+
"print(dct)"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 31,
96+
"id": "aa490d64",
97+
"metadata": {},
98+
"outputs": [
99+
{
100+
"name": "stdout",
101+
"output_type": "stream",
102+
"text": [
103+
"OrderedDict([('188', 88), ('107', 2), ('123', 3), ('897', 8), ('091', 10), ('876', 20)])\n"
104+
]
105+
}
106+
],
107+
"source": [
108+
"from collections import OrderedDict\n",
109+
"dict = OrderedDict({'107':2,'123':3,'897':8,'091':10,'876':20})\n",
110+
"dict.update({'188':88})\n",
111+
"dict.move_to_end('188',last=False)\n",
112+
"print(dict)"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": 71,
118+
"id": "dcbb610f",
119+
"metadata": {},
120+
"outputs": [],
121+
"source": [
122+
"from collections import OrderedDict\n",
123+
"\n",
124+
"def checkOrder(input, pattern):\n",
125+
"# create empty OrderedDict\n",
126+
"# output will be like {'a': None,'b': None, 'c': None}\n",
127+
" dict = OrderedDict.fromkeys(input)\n",
128+
"# traverse generated OrderedDict parallel with\n",
129+
"# pattern string to check if order of characters\n",
130+
"# are same or not\n",
131+
" ptrlen = 0\n",
132+
" for key,value in dict.items():\n",
133+
" if (key == pattern[ptrlen]):\n",
134+
" ptrlen = ptrlen + 1\n",
135+
"# check if we have traverse complete\n",
136+
"# pattern string\n",
137+
" if (ptrlen == (len(pattern))):\n",
138+
" return 'true'\n",
139+
"\n",
140+
"# if we come out from for loop that means\n",
141+
"# order was mismatched\n",
142+
" return 'false'"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": 73,
148+
"id": "02b39e1b",
149+
"metadata": {},
150+
"outputs": [
151+
{
152+
"name": "stdout",
153+
"output_type": "stream",
154+
"text": [
155+
"false\n"
156+
]
157+
}
158+
],
159+
"source": [
160+
"input = 'engineers rock'\n",
161+
"pattern = 'gsr'\n",
162+
"print (checkOrder(input,pattern))"
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": 76,
168+
"id": "f02976b8",
169+
"metadata": {},
170+
"outputs": [
171+
{
172+
"name": "stdout",
173+
"output_type": "stream",
174+
"text": [
175+
"a b c "
176+
]
177+
}
178+
],
179+
"source": [
180+
"dit={'a': 'Apple', 'c': 'Cat','b': 'Ball'}\n",
181+
"for i in sorted(dit.keys()):\n",
182+
" print(i,end=' ')"
183+
]
184+
}
185+
],
186+
"metadata": {
187+
"kernelspec": {
188+
"display_name": "Python 3",
189+
"language": "python",
190+
"name": "python3"
191+
},
192+
"language_info": {
193+
"codemirror_mode": {
194+
"name": "ipython",
195+
"version": 3
196+
},
197+
"file_extension": ".py",
198+
"mimetype": "text/x-python",
199+
"name": "python",
200+
"nbconvert_exporter": "python",
201+
"pygments_lexer": "ipython3",
202+
"version": "3.6.9"
203+
}
204+
},
205+
"nbformat": 4,
206+
"nbformat_minor": 5
207+
}

0 commit comments

Comments
 (0)