├── Blog Project.zip
├── Gagan - Vegan Store Project.rar
├── GaganGowda.py.zip
├── Library Management System FC.xml
├── Practise Problems 1 - Conditional Statements - Solutions.ipynb
├── Project - Edyoda Stories Page Codes.rar
├── Project - Edyoda stories _GaganGwdaHR.rar
├── README.md
├── Session 10 - Functions.ipynb
├── Session 11 - Functions Problems.ipynb
├── Session 12 - Problems.ipynb
├── Session 14 - Functions.ipynb
├── Session 15 - Test File Operations.ipynb
├── Session 16 - Regular Expression.ipynb
├── Session 18 - Map - Filter and Lambda.ipynb
├── Session 19 - Problem solving.ipynb
├── Session 21 - Class and Object.ipynb
├── Session 22 - OOP Part2.ipynb
├── Session 23 - Part3 OOP.ipynb
├── Session 26 - Iterators Decorators and Generators.ipynb
├── Session 3 - Conditional Statements and looping Statements.ipynb
├── Session 4 - Looping Statements.ipynb
├── Session 7 - Tuple , Dict.ipynb
├── Session 9 - Problem Solving Session.ipynb
├── blog.txt
├── bs.py
├── python interview questions.txt
├── session 1 - basics.ipynb
├── session 2 - Python Basics.ipynb
├── session 5 - Str.ipynb
├── session 6 - List.ipynb
└── session 8 - Sets.ipynb
/Blog Project.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GaganGowdaHR/Gagan-python-django-code/2934a225fd282dc9c0b0c1436a17388a3bc7525f/Blog Project.zip
--------------------------------------------------------------------------------
/Gagan - Vegan Store Project.rar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GaganGowdaHR/Gagan-python-django-code/2934a225fd282dc9c0b0c1436a17388a3bc7525f/Gagan - Vegan Store Project.rar
--------------------------------------------------------------------------------
/GaganGowda.py.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GaganGowdaHR/Gagan-python-django-code/2934a225fd282dc9c0b0c1436a17388a3bc7525f/GaganGowda.py.zip
--------------------------------------------------------------------------------
/Library Management System FC.xml:
--------------------------------------------------------------------------------
1 | 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
--------------------------------------------------------------------------------
/Practise Problems 1 - Conditional Statements - Solutions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "1.Given two numbers , print their sum. However , if the two numbers are the same , return doublt their sum"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 2,
15 | "metadata": {},
16 | "outputs": [
17 | {
18 | "name": "stdout",
19 | "output_type": "stream",
20 | "text": [
21 | "800\n"
22 | ]
23 | }
24 | ],
25 | "source": [
26 | "num1 = 200\n",
27 | "num2 = 200\n",
28 | "\n",
29 | "if num1 == num2:\n",
30 | " print((num1 + num2) * 2)\n",
31 | "else:\n",
32 | " print(num1 + num2)\n"
33 | ]
34 | },
35 | {
36 | "cell_type": "code",
37 | "execution_count": null,
38 | "metadata": {},
39 | "outputs": [],
40 | "source": [
41 | "2.Given a Cost price and Selling price of a product . Write program to calculate profit or lose"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": 5,
47 | "metadata": {},
48 | "outputs": [
49 | {
50 | "name": "stdout",
51 | "output_type": "stream",
52 | "text": [
53 | "profit of: 700\n"
54 | ]
55 | }
56 | ],
57 | "source": [
58 | "cost_price = 500\n",
59 | "selling_price = 1200\n",
60 | "profit = selling_price > cost_price\n",
61 | "loss = cost_price > selling_price\n",
62 | "if selling_price > cost_price:\n",
63 | " print(\"profit of:\",selling_price - cost_price)\n",
64 | "elif cost_price > selling_price:\n",
65 | " print(\"loss of:\",cost_price - selling_price)\n",
66 | "else:\n",
67 | " print(\"no profit no loss\")"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": null,
73 | "metadata": {},
74 | "outputs": [],
75 | "source": [
76 | "3.Write a program to input basic salary of an employee and calculate gross salary according to given conditions.\n",
77 | "Basic Salary <= 10000 : HRA = 20%, DA = 80%\n",
78 | "Basic Salary is between 10001 to 20000 : HRA = 25% , DA = 90% \n",
79 | "Basic Salary >= 20001 : HRA = 30% , DA = 95%"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": 21,
85 | "metadata": {},
86 | "outputs": [
87 | {
88 | "name": "stdout",
89 | "output_type": "stream",
90 | "text": [
91 | "43000.0\n"
92 | ]
93 | }
94 | ],
95 | "source": [
96 | "basic_salary = 20000\n",
97 | "\n",
98 | "if basic_salary <= 10000:\n",
99 | " hra = (basic_salary * 20) / 100\n",
100 | " da = (basic_salary * 80) / 100\n",
101 | "elif basic_salary >= 20000:\n",
102 | " hra = (basic_salary * 25) / 100\n",
103 | " da = (basic_salary * 90) / 100\n",
104 | "else:\n",
105 | " hra = (basic_salary * 30) / 100\n",
106 | " da = (basic_salary * 95) / 100\n",
107 | " \n",
108 | "gross_salary = basic_salary + hra + da\n",
109 | "print(gross_salary) "
110 | ]
111 | },
112 | {
113 | "cell_type": "code",
114 | "execution_count": null,
115 | "metadata": {},
116 | "outputs": [],
117 | "source": [
118 | "4.Write a program to check if given year is leap year or not\n",
119 | " leap year : a year is said to be leap if the year is exactly divisible by 4 but not divisible by 100"
120 | ]
121 | },
122 | {
123 | "cell_type": "code",
124 | "execution_count": 46,
125 | "metadata": {},
126 | "outputs": [
127 | {
128 | "name": "stdout",
129 | "output_type": "stream",
130 | "text": [
131 | "leap Year\n"
132 | ]
133 | }
134 | ],
135 | "source": [
136 | "year = 2000\n",
137 | "\n",
138 | "if year % 4 == 0 and year % 100 != 0:\n",
139 | " print(\"leap Year\")\n",
140 | "elif year % 4 == 0 and year % 100 == 0 and year % 400 == 0:\n",
141 | " print(\"leap Year\")\n",
142 | "else:\n",
143 | " print(\"not a leap year\")"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {},
150 | "outputs": [],
151 | "source": [
152 | "5.Write a program to check whether the given triangle is equilateral , scalene or isosceles. \n",
153 | "A triangle is said equilateral , if all the sides of the triangle is equal.if a, b, c are three sides of triangle.Then the \n",
154 | "triangle is equilateral only if a == b == c.\n",
155 | "A triangle is said to be isosceles, only if two sides are equal. like a == b , a == b or b == c\n",
156 | "A traingle is said to be scalene , only if no sides are equal."
157 | ]
158 | },
159 | {
160 | "cell_type": "code",
161 | "execution_count": 52,
162 | "metadata": {},
163 | "outputs": [
164 | {
165 | "name": "stdout",
166 | "output_type": "stream",
167 | "text": [
168 | "Scalene triangle\n"
169 | ]
170 | }
171 | ],
172 | "source": [
173 | "side_a = 4\n",
174 | "side_b = 7\n",
175 | "side_c = 5\n",
176 | "\n",
177 | "if side_a == side_b == side_c:\n",
178 | " print(\"equilateral triangle\")\n",
179 | "elif side_a == side_b or side_a == side_c or side_b == side_c:\n",
180 | " print(\"isosceles triangle\")\n",
181 | "else:\n",
182 | " print(\"Scalene triangle\")"
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.7.4"
203 | }
204 | },
205 | "nbformat": 4,
206 | "nbformat_minor": 2
207 | }
208 |
--------------------------------------------------------------------------------
/Project - Edyoda Stories Page Codes.rar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GaganGowdaHR/Gagan-python-django-code/2934a225fd282dc9c0b0c1436a17388a3bc7525f/Project - Edyoda Stories Page Codes.rar
--------------------------------------------------------------------------------
/Project - Edyoda stories _GaganGwdaHR.rar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GaganGowdaHR/Gagan-python-django-code/2934a225fd282dc9c0b0c1436a17388a3bc7525f/Project - Edyoda stories _GaganGwdaHR.rar
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Gagan-python-django-code
2 | my code
3 |
--------------------------------------------------------------------------------
/Session 10 - Functions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 5,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "a = 10\n",
10 | "b = 20"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 6,
16 | "metadata": {},
17 | "outputs": [
18 | {
19 | "data": {
20 | "text/plain": [
21 | "30"
22 | ]
23 | },
24 | "execution_count": 6,
25 | "metadata": {},
26 | "output_type": "execute_result"
27 | }
28 | ],
29 | "source": [
30 | "a + b"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 7,
36 | "metadata": {},
37 | "outputs": [
38 | {
39 | "data": {
40 | "text/plain": [
41 | "200"
42 | ]
43 | },
44 | "execution_count": 7,
45 | "metadata": {},
46 | "output_type": "execute_result"
47 | }
48 | ],
49 | "source": [
50 | "a * b"
51 | ]
52 | },
53 | {
54 | "cell_type": "code",
55 | "execution_count": 8,
56 | "metadata": {},
57 | "outputs": [
58 | {
59 | "data": {
60 | "text/plain": [
61 | "0.5"
62 | ]
63 | },
64 | "execution_count": 8,
65 | "metadata": {},
66 | "output_type": "execute_result"
67 | }
68 | ],
69 | "source": [
70 | "a / b"
71 | ]
72 | },
73 | {
74 | "cell_type": "code",
75 | "execution_count": 9,
76 | "metadata": {},
77 | "outputs": [],
78 | "source": [
79 | "def mysum(a,b):\n",
80 | " return a+b"
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": 10,
86 | "metadata": {},
87 | "outputs": [
88 | {
89 | "data": {
90 | "text/plain": [
91 | "30"
92 | ]
93 | },
94 | "execution_count": 10,
95 | "metadata": {},
96 | "output_type": "execute_result"
97 | }
98 | ],
99 | "source": [
100 | "mysum(10,20)"
101 | ]
102 | },
103 | {
104 | "cell_type": "code",
105 | "execution_count": 11,
106 | "metadata": {},
107 | "outputs": [],
108 | "source": [
109 | "def mymult(a,b):\n",
110 | " return a * b"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": 12,
116 | "metadata": {},
117 | "outputs": [
118 | {
119 | "data": {
120 | "text/plain": [
121 | "600"
122 | ]
123 | },
124 | "execution_count": 12,
125 | "metadata": {},
126 | "output_type": "execute_result"
127 | }
128 | ],
129 | "source": [
130 | "mymult(20,30)"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": 13,
136 | "metadata": {},
137 | "outputs": [
138 | {
139 | "data": {
140 | "text/plain": [
141 | "1200"
142 | ]
143 | },
144 | "execution_count": 13,
145 | "metadata": {},
146 | "output_type": "execute_result"
147 | }
148 | ],
149 | "source": [
150 | "mymult(30,40)"
151 | ]
152 | },
153 | {
154 | "cell_type": "code",
155 | "execution_count": 14,
156 | "metadata": {},
157 | "outputs": [],
158 | "source": [
159 | "res = mysum(30,20)"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": 15,
165 | "metadata": {},
166 | "outputs": [
167 | {
168 | "data": {
169 | "text/plain": [
170 | "50"
171 | ]
172 | },
173 | "execution_count": 15,
174 | "metadata": {},
175 | "output_type": "execute_result"
176 | }
177 | ],
178 | "source": [
179 | "res"
180 | ]
181 | },
182 | {
183 | "cell_type": "code",
184 | "execution_count": 16,
185 | "metadata": {},
186 | "outputs": [],
187 | "source": [
188 | "def mycal(a,b):\n",
189 | " mult = mymult(a,b)\n",
190 | " msum = mysum(a,b)\n",
191 | " return mult,msum"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "execution_count": 17,
197 | "metadata": {},
198 | "outputs": [],
199 | "source": [
200 | "mymult, mysum = mycal(10,20)"
201 | ]
202 | },
203 | {
204 | "cell_type": "code",
205 | "execution_count": 18,
206 | "metadata": {},
207 | "outputs": [
208 | {
209 | "data": {
210 | "text/plain": [
211 | "200"
212 | ]
213 | },
214 | "execution_count": 18,
215 | "metadata": {},
216 | "output_type": "execute_result"
217 | }
218 | ],
219 | "source": [
220 | "mymult"
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": 19,
226 | "metadata": {},
227 | "outputs": [
228 | {
229 | "data": {
230 | "text/plain": [
231 | "30"
232 | ]
233 | },
234 | "execution_count": 19,
235 | "metadata": {},
236 | "output_type": "execute_result"
237 | }
238 | ],
239 | "source": [
240 | "mysum"
241 | ]
242 | },
243 | {
244 | "cell_type": "code",
245 | "execution_count": 20,
246 | "metadata": {},
247 | "outputs": [],
248 | "source": [
249 | "def checkEvenNumber(num):\n",
250 | " if num % 2 == 0:\n",
251 | " return True\n",
252 | " else:\n",
253 | " return False"
254 | ]
255 | },
256 | {
257 | "cell_type": "code",
258 | "execution_count": 21,
259 | "metadata": {},
260 | "outputs": [
261 | {
262 | "data": {
263 | "text/plain": [
264 | "True"
265 | ]
266 | },
267 | "execution_count": 21,
268 | "metadata": {},
269 | "output_type": "execute_result"
270 | }
271 | ],
272 | "source": [
273 | "checkEvenNumber(22)"
274 | ]
275 | },
276 | {
277 | "cell_type": "code",
278 | "execution_count": 27,
279 | "metadata": {},
280 | "outputs": [],
281 | "source": [
282 | "Take two numbers\n",
283 | "Check if first number is even\n",
284 | "If first number is even, multiply them\n",
285 | "Else product them\n",
286 | "Return the result"
287 | ]
288 | },
289 | {
290 | "cell_type": "code",
291 | "execution_count": 23,
292 | "metadata": {},
293 | "outputs": [],
294 | "source": [
295 | "def myMainCode(num1, num2):\n",
296 | " checkEven = checkEvenNumber(num1)\n",
297 | " \n",
298 | " if checkEven:\n",
299 | " res = mymult(num1, num2)\n",
300 | " else:\n",
301 | " res = mysum(num1, num2)\n",
302 | " \n",
303 | " return res"
304 | ]
305 | },
306 | {
307 | "cell_type": "code",
308 | "execution_count": 30,
309 | "metadata": {},
310 | "outputs": [
311 | {
312 | "ename": "TypeError",
313 | "evalue": "'int' object is not callable",
314 | "output_type": "error",
315 | "traceback": [
316 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
317 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
318 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmyMainCode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m200\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
319 | "\u001b[1;32m\u001b[0m in \u001b[0;36mmyMainCode\u001b[1;34m(num1, num2)\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcheckEven\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmymult\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnum1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnum2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmysum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnum1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnum2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
320 | "\u001b[1;31mTypeError\u001b[0m: 'int' object is not callable"
321 | ]
322 | }
323 | ],
324 | "source": [
325 | "myMainCode(100,200)"
326 | ]
327 | },
328 | {
329 | "cell_type": "code",
330 | "execution_count": 26,
331 | "metadata": {},
332 | "outputs": [],
333 | "source": [
334 | "Problem Statement :\n",
335 | "\n",
336 | "Jack & Jill Game\n",
337 | "Jack increments by 2\n",
338 | "Jill decrements by 1"
339 | ]
340 | },
341 | {
342 | "cell_type": "code",
343 | "execution_count": 48,
344 | "metadata": {},
345 | "outputs": [],
346 | "source": [
347 | "value = 0 \n",
348 | "\n",
349 | "def jackFunc():\n",
350 | " global value\n",
351 | " value += 2\n",
352 | " \n",
353 | "def jillFunc():\n",
354 | " global value\n",
355 | " value -= 1"
356 | ]
357 | },
358 | {
359 | "cell_type": "code",
360 | "execution_count": 49,
361 | "metadata": {},
362 | "outputs": [],
363 | "source": [
364 | "i = 0\n",
365 | "while i < 10:\n",
366 | " jackFunc()\n",
367 | " i += 1"
368 | ]
369 | },
370 | {
371 | "cell_type": "code",
372 | "execution_count": 51,
373 | "metadata": {},
374 | "outputs": [
375 | {
376 | "data": {
377 | "text/plain": [
378 | "20"
379 | ]
380 | },
381 | "execution_count": 51,
382 | "metadata": {},
383 | "output_type": "execute_result"
384 | }
385 | ],
386 | "source": [
387 | "value"
388 | ]
389 | },
390 | {
391 | "cell_type": "code",
392 | "execution_count": 52,
393 | "metadata": {},
394 | "outputs": [],
395 | "source": [
396 | "value = 0 \n",
397 | "\n",
398 | "def jackFunc(value):\n",
399 | " value += 2\n",
400 | " return value\n",
401 | " \n",
402 | "def jillFunc(value):\n",
403 | " value -= 1\n",
404 | " return value"
405 | ]
406 | },
407 | {
408 | "cell_type": "code",
409 | "execution_count": 53,
410 | "metadata": {},
411 | "outputs": [],
412 | "source": [
413 | "i = 0\n",
414 | "while i < 10:\n",
415 | " value = jillFunc(value)\n",
416 | " i += 1"
417 | ]
418 | },
419 | {
420 | "cell_type": "code",
421 | "execution_count": 54,
422 | "metadata": {},
423 | "outputs": [
424 | {
425 | "data": {
426 | "text/plain": [
427 | "-10"
428 | ]
429 | },
430 | "execution_count": 54,
431 | "metadata": {},
432 | "output_type": "execute_result"
433 | }
434 | ],
435 | "source": [
436 | "value"
437 | ]
438 | },
439 | {
440 | "cell_type": "code",
441 | "execution_count": null,
442 | "metadata": {},
443 | "outputs": [],
444 | "source": [
445 | "\n",
446 | "Problem Statement :\n",
447 | "\n",
448 | "1. Write a function a takes a string\n",
449 | "2. Check if the string contains a vowel ( a )\n",
450 | "3. If it does, print it once \n",
451 | "4. Or, print the word two times\n",
452 | "\n",
453 | "Solution :\n",
454 | "\n",
455 | "1. Write a function to check if the word contains vowel\n",
456 | "2. Use the output from above to print desired number of times"
457 | ]
458 | },
459 | {
460 | "cell_type": "code",
461 | "execution_count": 55,
462 | "metadata": {},
463 | "outputs": [],
464 | "source": [
465 | "def checkIfWordConatins(word, checkalpha):\n",
466 | " for ch in word:\n",
467 | " if ch in checkalpha:\n",
468 | " return True\n",
469 | " return False\n"
470 | ]
471 | },
472 | {
473 | "cell_type": "code",
474 | "execution_count": 56,
475 | "metadata": {},
476 | "outputs": [
477 | {
478 | "data": {
479 | "text/plain": [
480 | "False"
481 | ]
482 | },
483 | "execution_count": 56,
484 | "metadata": {},
485 | "output_type": "execute_result"
486 | }
487 | ],
488 | "source": [
489 | "checkIfWordConatins('sst','xyz')"
490 | ]
491 | },
492 | {
493 | "cell_type": "code",
494 | "execution_count": 57,
495 | "metadata": {},
496 | "outputs": [],
497 | "source": [
498 | "def printWordTimes(word,times):\n",
499 | " for t in range(times):\n",
500 | " print (word)"
501 | ]
502 | },
503 | {
504 | "cell_type": "code",
505 | "execution_count": 58,
506 | "metadata": {},
507 | "outputs": [],
508 | "source": [
509 | "def myUtilityCode(word, checkalpha, times):\n",
510 | " check = checkIfWordConatins(word, checkalpha)\n",
511 | " if check:\n",
512 | " print (word)\n",
513 | " else:\n",
514 | " printWordTimes(word, times)"
515 | ]
516 | },
517 | {
518 | "cell_type": "code",
519 | "execution_count": 59,
520 | "metadata": {},
521 | "outputs": [
522 | {
523 | "name": "stdout",
524 | "output_type": "stream",
525 | "text": [
526 | "Hello\n"
527 | ]
528 | }
529 | ],
530 | "source": [
531 | "myUtilityCode('Hello','el',3)"
532 | ]
533 | },
534 | {
535 | "cell_type": "code",
536 | "execution_count": 60,
537 | "metadata": {},
538 | "outputs": [
539 | {
540 | "name": "stdout",
541 | "output_type": "stream",
542 | "text": [
543 | "Hello\n",
544 | "Hello\n",
545 | "Hello\n"
546 | ]
547 | }
548 | ],
549 | "source": [
550 | "myUtilityCode('Hello','xy',3)"
551 | ]
552 | },
553 | {
554 | "cell_type": "code",
555 | "execution_count": null,
556 | "metadata": {},
557 | "outputs": [],
558 | "source": [
559 | "Default Params"
560 | ]
561 | },
562 | {
563 | "cell_type": "code",
564 | "execution_count": 61,
565 | "metadata": {},
566 | "outputs": [],
567 | "source": [
568 | "def printMyDetails(name, age=18, location='Karnataka'):\n",
569 | " print (name,age,location)"
570 | ]
571 | },
572 | {
573 | "cell_type": "code",
574 | "execution_count": 62,
575 | "metadata": {},
576 | "outputs": [
577 | {
578 | "name": "stdout",
579 | "output_type": "stream",
580 | "text": [
581 | "Edyoda 3 Bangalore\n"
582 | ]
583 | }
584 | ],
585 | "source": [
586 | "printMyDetails('Edyoda',3,'Bangalore')"
587 | ]
588 | },
589 | {
590 | "cell_type": "code",
591 | "execution_count": 63,
592 | "metadata": {},
593 | "outputs": [
594 | {
595 | "name": "stdout",
596 | "output_type": "stream",
597 | "text": [
598 | "Edyoda abc Karnataka\n"
599 | ]
600 | }
601 | ],
602 | "source": [
603 | "printMyDetails('Edyoda','abc')"
604 | ]
605 | },
606 | {
607 | "cell_type": "code",
608 | "execution_count": null,
609 | "metadata": {},
610 | "outputs": [],
611 | "source": [
612 | "Named Parameters"
613 | ]
614 | },
615 | {
616 | "cell_type": "code",
617 | "execution_count": 64,
618 | "metadata": {},
619 | "outputs": [],
620 | "source": [
621 | "def printMyDetails(name, age=18, location='Karnataka'):\n",
622 | " print (name,age)"
623 | ]
624 | },
625 | {
626 | "cell_type": "code",
627 | "execution_count": 65,
628 | "metadata": {},
629 | "outputs": [
630 | {
631 | "name": "stdout",
632 | "output_type": "stream",
633 | "text": [
634 | "abcdef 20\n"
635 | ]
636 | }
637 | ],
638 | "source": [
639 | "printMyDetails(age=20, name='abcdef', location='Mumbai')"
640 | ]
641 | },
642 | {
643 | "cell_type": "code",
644 | "execution_count": null,
645 | "metadata": {},
646 | "outputs": [],
647 | "source": [
648 | "Variable Arguments"
649 | ]
650 | },
651 | {
652 | "cell_type": "code",
653 | "execution_count": null,
654 | "metadata": {},
655 | "outputs": [],
656 | "source": [
657 | "*packing"
658 | ]
659 | },
660 | {
661 | "cell_type": "code",
662 | "execution_count": 66,
663 | "metadata": {},
664 | "outputs": [],
665 | "source": [
666 | "def mySum(*args):\n",
667 | " res = 0\n",
668 | " for e in args:\n",
669 | " res += e\n",
670 | " return res"
671 | ]
672 | },
673 | {
674 | "cell_type": "code",
675 | "execution_count": 67,
676 | "metadata": {},
677 | "outputs": [],
678 | "source": [
679 | "def mySum(*args):\n",
680 | " return sum(args)"
681 | ]
682 | },
683 | {
684 | "cell_type": "code",
685 | "execution_count": 68,
686 | "metadata": {},
687 | "outputs": [
688 | {
689 | "data": {
690 | "text/plain": [
691 | "30"
692 | ]
693 | },
694 | "execution_count": 68,
695 | "metadata": {},
696 | "output_type": "execute_result"
697 | }
698 | ],
699 | "source": [
700 | "mySum(10,20)"
701 | ]
702 | },
703 | {
704 | "cell_type": "code",
705 | "execution_count": 69,
706 | "metadata": {},
707 | "outputs": [
708 | {
709 | "data": {
710 | "text/plain": [
711 | "60"
712 | ]
713 | },
714 | "execution_count": 69,
715 | "metadata": {},
716 | "output_type": "execute_result"
717 | }
718 | ],
719 | "source": [
720 | "mySum(10,20,30)"
721 | ]
722 | },
723 | {
724 | "cell_type": "code",
725 | "execution_count": null,
726 | "metadata": {},
727 | "outputs": [],
728 | "source": [
729 | "* Unpacking"
730 | ]
731 | },
732 | {
733 | "cell_type": "code",
734 | "execution_count": 70,
735 | "metadata": {},
736 | "outputs": [],
737 | "source": [
738 | "l = ['blore','edyoda',10]"
739 | ]
740 | },
741 | {
742 | "cell_type": "code",
743 | "execution_count": 71,
744 | "metadata": {},
745 | "outputs": [],
746 | "source": [
747 | "def printDetails(loc, name, age):\n",
748 | " print (loc, name, age)"
749 | ]
750 | },
751 | {
752 | "cell_type": "code",
753 | "execution_count": 72,
754 | "metadata": {},
755 | "outputs": [
756 | {
757 | "name": "stdout",
758 | "output_type": "stream",
759 | "text": [
760 | "blore edyoda 10\n"
761 | ]
762 | }
763 | ],
764 | "source": [
765 | "printDetails(*l)"
766 | ]
767 | },
768 | {
769 | "cell_type": "code",
770 | "execution_count": null,
771 | "metadata": {},
772 | "outputs": [],
773 | "source": [
774 | "Named Packing"
775 | ]
776 | },
777 | {
778 | "cell_type": "code",
779 | "execution_count": 73,
780 | "metadata": {},
781 | "outputs": [],
782 | "source": [
783 | "def myFunc(name, loc, age):\n",
784 | " if name == 'abc':\n",
785 | " print (name)\n",
786 | " else:\n",
787 | " print (loc,age)"
788 | ]
789 | },
790 | {
791 | "cell_type": "code",
792 | "execution_count": 74,
793 | "metadata": {},
794 | "outputs": [
795 | {
796 | "name": "stdout",
797 | "output_type": "stream",
798 | "text": [
799 | "abc\n"
800 | ]
801 | }
802 | ],
803 | "source": [
804 | "myFunc(loc='mumbai',age=10,name='abc')"
805 | ]
806 | },
807 | {
808 | "cell_type": "code",
809 | "execution_count": 75,
810 | "metadata": {},
811 | "outputs": [],
812 | "source": [
813 | "def myFunc(**kwargs):\n",
814 | " if kwargs['name'] == 'abc':\n",
815 | " print (kwargs['name'])\n",
816 | " else:\n",
817 | " print (kwargs['loc'], kwargs['age'])\n",
818 | " \n",
819 | " if 'name' in kwargs:\n",
820 | " print (kwargs['name'])"
821 | ]
822 | },
823 | {
824 | "cell_type": "code",
825 | "execution_count": 76,
826 | "metadata": {},
827 | "outputs": [
828 | {
829 | "name": "stdout",
830 | "output_type": "stream",
831 | "text": [
832 | "mumbai 10\n",
833 | "bcd\n"
834 | ]
835 | }
836 | ],
837 | "source": [
838 | "myFunc(loc='mumbai',age=10,name='bcd')"
839 | ]
840 | },
841 | {
842 | "cell_type": "code",
843 | "execution_count": 77,
844 | "metadata": {},
845 | "outputs": [
846 | {
847 | "name": "stdout",
848 | "output_type": "stream",
849 | "text": [
850 | "abc\n",
851 | "abc\n"
852 | ]
853 | }
854 | ],
855 | "source": [
856 | "myFunc(location='mumbai',age=10,name='abc')"
857 | ]
858 | },
859 | {
860 | "cell_type": "code",
861 | "execution_count": null,
862 | "metadata": {},
863 | "outputs": [],
864 | "source": [
865 | "Problem :\n",
866 | "\n",
867 | "* mySumFunc(10,20,11,21,23)\n",
868 | "* mySumFunc(10,20,11,21,23,445,2323)\n",
869 | "* Multiply all the even numbers"
870 | ]
871 | },
872 | {
873 | "cell_type": "code",
874 | "execution_count": 78,
875 | "metadata": {},
876 | "outputs": [],
877 | "source": [
878 | "def myMultFunc(*nums):\n",
879 | " res = 1\n",
880 | " for num in nums:\n",
881 | " if num %2 == 0:\n",
882 | " res *= num\n",
883 | " return res"
884 | ]
885 | },
886 | {
887 | "cell_type": "code",
888 | "execution_count": 79,
889 | "metadata": {},
890 | "outputs": [
891 | {
892 | "data": {
893 | "text/plain": [
894 | "4400"
895 | ]
896 | },
897 | "execution_count": 79,
898 | "metadata": {},
899 | "output_type": "execute_result"
900 | }
901 | ],
902 | "source": [
903 | "myMultFunc(10,20,22,23)"
904 | ]
905 | },
906 | {
907 | "cell_type": "code",
908 | "execution_count": null,
909 | "metadata": {},
910 | "outputs": [],
911 | "source": []
912 | }
913 | ],
914 | "metadata": {
915 | "kernelspec": {
916 | "display_name": "Python 3",
917 | "language": "python",
918 | "name": "python3"
919 | },
920 | "language_info": {
921 | "codemirror_mode": {
922 | "name": "ipython",
923 | "version": 3
924 | },
925 | "file_extension": ".py",
926 | "mimetype": "text/x-python",
927 | "name": "python",
928 | "nbconvert_exporter": "python",
929 | "pygments_lexer": "ipython3",
930 | "version": "3.7.4"
931 | }
932 | },
933 | "nbformat": 4,
934 | "nbformat_minor": 2
935 | }
936 |
--------------------------------------------------------------------------------
/Session 11 - Functions Problems.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "def vargFunc(*args):\n",
10 | " print (type(args))"
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 2,
16 | "metadata": {},
17 | "outputs": [
18 | {
19 | "name": "stdout",
20 | "output_type": "stream",
21 | "text": [
22 | "\n"
23 | ]
24 | }
25 | ],
26 | "source": [
27 | "vargFunc(1,2,3,4)"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": 3,
33 | "metadata": {},
34 | "outputs": [
35 | {
36 | "name": "stdout",
37 | "output_type": "stream",
38 | "text": [
39 | "\n"
40 | ]
41 | }
42 | ],
43 | "source": [
44 | "vargFunc(4,5,6,7,78)"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "metadata": {},
51 | "outputs": [],
52 | "source": [
53 | "Problems related to functions\n",
54 | "\n",
55 | "Call a function with multiple words\n",
56 | "Return a string separated by spaces containing only the words of even length"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": 4,
62 | "metadata": {},
63 | "outputs": [],
64 | "source": [
65 | "def evenWordsCollector(*args):\n",
66 | " l = []\n",
67 | " for word in args:\n",
68 | " if ifWordEven(word):\n",
69 | " l.append(word)\n",
70 | " res = ' '.join(l)\n",
71 | " return res"
72 | ]
73 | },
74 | {
75 | "cell_type": "code",
76 | "execution_count": 5,
77 | "metadata": {},
78 | "outputs": [],
79 | "source": [
80 | "def ifWordEven(word):\n",
81 | " if len(word) % 2 == 0:\n",
82 | " return True\n",
83 | " else:\n",
84 | " return False"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": 6,
90 | "metadata": {},
91 | "outputs": [
92 | {
93 | "data": {
94 | "text/plain": [
95 | "'abcd jklm'"
96 | ]
97 | },
98 | "execution_count": 6,
99 | "metadata": {},
100 | "output_type": "execute_result"
101 | }
102 | ],
103 | "source": [
104 | "evenWordsCollector('abc','def','abcd','jklm')"
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": 7,
110 | "metadata": {},
111 | "outputs": [
112 | {
113 | "data": {
114 | "text/plain": [
115 | "True"
116 | ]
117 | },
118 | "execution_count": 7,
119 | "metadata": {},
120 | "output_type": "execute_result"
121 | }
122 | ],
123 | "source": [
124 | "ifWordEven('Hell')"
125 | ]
126 | },
127 | {
128 | "cell_type": "code",
129 | "execution_count": 8,
130 | "metadata": {},
131 | "outputs": [
132 | {
133 | "data": {
134 | "text/plain": [
135 | "'abcd jklm hjhj'"
136 | ]
137 | },
138 | "execution_count": 8,
139 | "metadata": {},
140 | "output_type": "execute_result"
141 | }
142 | ],
143 | "source": [
144 | "evenWordsCollector('abc','def','abcd','jklm','hjhj')"
145 | ]
146 | },
147 | {
148 | "cell_type": "code",
149 | "execution_count": null,
150 | "metadata": {},
151 | "outputs": [],
152 | "source": [
153 | "Problem Statement\n",
154 | "\n",
155 | "Take Employee Data & put them in a list"
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": 9,
161 | "metadata": {},
162 | "outputs": [],
163 | "source": [
164 | "def createEmpData(list_emps, **kwargs):\n",
165 | " list_emps.append(kwargs)"
166 | ]
167 | },
168 | {
169 | "cell_type": "code",
170 | "execution_count": 10,
171 | "metadata": {},
172 | "outputs": [],
173 | "source": [
174 | "list_emps = []\n",
175 | "\n",
176 | "createEmpData(list_emps, name='abc',age=20)"
177 | ]
178 | },
179 | {
180 | "cell_type": "code",
181 | "execution_count": 11,
182 | "metadata": {},
183 | "outputs": [
184 | {
185 | "data": {
186 | "text/plain": [
187 | "[{'name': 'abc', 'age': 20}]"
188 | ]
189 | },
190 | "execution_count": 11,
191 | "metadata": {},
192 | "output_type": "execute_result"
193 | }
194 | ],
195 | "source": [
196 | "list_emps"
197 | ]
198 | },
199 | {
200 | "cell_type": "code",
201 | "execution_count": 12,
202 | "metadata": {},
203 | "outputs": [],
204 | "source": [
205 | "createEmpData(list_emps, name='def',age=20,location='blore')"
206 | ]
207 | },
208 | {
209 | "cell_type": "code",
210 | "execution_count": 13,
211 | "metadata": {},
212 | "outputs": [
213 | {
214 | "data": {
215 | "text/plain": [
216 | "[{'name': 'abc', 'age': 20}, {'name': 'def', 'age': 20, 'location': 'blore'}]"
217 | ]
218 | },
219 | "execution_count": 13,
220 | "metadata": {},
221 | "output_type": "execute_result"
222 | }
223 | ],
224 | "source": [
225 | "list_emps"
226 | ]
227 | },
228 | {
229 | "cell_type": "code",
230 | "execution_count": 15,
231 | "metadata": {},
232 | "outputs": [],
233 | "source": [
234 | "createEmpData(list_emps, name='def',age=20,salary=100000)\n",
235 | "createEmpData(list_emps, name='def',age=20,salary=500000)"
236 | ]
237 | },
238 | {
239 | "cell_type": "code",
240 | "execution_count": 16,
241 | "metadata": {},
242 | "outputs": [
243 | {
244 | "data": {
245 | "text/plain": [
246 | "[{'name': 'abc', 'age': 20},\n",
247 | " {'name': 'def', 'age': 20, 'location': 'blore'},\n",
248 | " {'name': 'def', 'age': 20, 'salary': 100000},\n",
249 | " {'name': 'def', 'age': 20, 'salary': 500000}]"
250 | ]
251 | },
252 | "execution_count": 16,
253 | "metadata": {},
254 | "output_type": "execute_result"
255 | }
256 | ],
257 | "source": [
258 | "list_emps"
259 | ]
260 | },
261 | {
262 | "cell_type": "code",
263 | "execution_count": 17,
264 | "metadata": {},
265 | "outputs": [
266 | {
267 | "name": "stdout",
268 | "output_type": "stream",
269 | "text": [
270 | "{'name': 'def', 'age': 20, 'location': 'blore'}\n"
271 | ]
272 | }
273 | ],
274 | "source": [
275 | "for emp in list_emps:\n",
276 | " if 'location' in emp:\n",
277 | " print (emp)"
278 | ]
279 | },
280 | {
281 | "cell_type": "code",
282 | "execution_count": 18,
283 | "metadata": {},
284 | "outputs": [],
285 | "source": [
286 | "# Print folks whose salary is >= 100000\n",
287 | "def getPeopleSalary(list_emps,salary=50000):\n",
288 | " res = []\n",
289 | " for emp in list_emps:\n",
290 | " if 'salary' in emp:\n",
291 | " if emp['salary'] >= salary:\n",
292 | " res.append(emp)\n",
293 | " return res"
294 | ]
295 | },
296 | {
297 | "cell_type": "code",
298 | "execution_count": 20,
299 | "metadata": {},
300 | "outputs": [
301 | {
302 | "data": {
303 | "text/plain": [
304 | "[{'name': 'def', 'age': 20, 'salary': 100000},\n",
305 | " {'name': 'def', 'age': 20, 'salary': 500000}]"
306 | ]
307 | },
308 | "execution_count": 20,
309 | "metadata": {},
310 | "output_type": "execute_result"
311 | }
312 | ],
313 | "source": [
314 | "getPeopleSalary(list_emps,100000)"
315 | ]
316 | },
317 | {
318 | "cell_type": "code",
319 | "execution_count": null,
320 | "metadata": {},
321 | "outputs": [],
322 | "source": [
323 | "Problem\n",
324 | "\n",
325 | "Store students's marks information in a list [{'name':'abc','maths':20,'eglish':30}, {}]\n",
326 | "Find topper in class\n",
327 | "\n",
328 | "Pseudo-Code\n",
329 | "\n",
330 | "AddStudent Function\n",
331 | "Calculate marks percentage\n",
332 | "Find Topper"
333 | ]
334 | },
335 | {
336 | "cell_type": "code",
337 | "execution_count": 21,
338 | "metadata": {},
339 | "outputs": [],
340 | "source": [
341 | "def createStudentData(list_students, **marks):\n",
342 | " list_students.append(marks)"
343 | ]
344 | },
345 | {
346 | "cell_type": "code",
347 | "execution_count": 22,
348 | "metadata": {},
349 | "outputs": [],
350 | "source": [
351 | "list_students = []\n",
352 | "createStudentData(list_students,name='david',maths=80, science=75,english=76)\n",
353 | "createStudentData(list_students,name='rohit',maths=90, science=85,english=66)\n",
354 | "createStudentData(list_students,name='raj',maths=40, science=55,english=56)\n",
355 | "createStudentData(list_students,name='yazhini',maths=80, science=88,english=76)\n"
356 | ]
357 | },
358 | {
359 | "cell_type": "code",
360 | "execution_count": 23,
361 | "metadata": {},
362 | "outputs": [
363 | {
364 | "data": {
365 | "text/plain": [
366 | "[{'name': 'david', 'maths': 80, 'science': 75, 'english': 76},\n",
367 | " {'name': 'rohit', 'maths': 90, 'science': 85, 'english': 66},\n",
368 | " {'name': 'raj', 'maths': 40, 'science': 55, 'english': 56},\n",
369 | " {'name': 'yazhini', 'maths': 80, 'science': 88, 'english': 76}]"
370 | ]
371 | },
372 | "execution_count": 23,
373 | "metadata": {},
374 | "output_type": "execute_result"
375 | }
376 | ],
377 | "source": [
378 | "list_students"
379 | ]
380 | },
381 | {
382 | "cell_type": "code",
383 | "execution_count": 24,
384 | "metadata": {},
385 | "outputs": [],
386 | "source": [
387 | "def calcMarksAvg(list_students):\n",
388 | " for student in list_students:\n",
389 | " total_marks = 0\n",
390 | " count = 0\n",
391 | " for k,v in student.items():\n",
392 | " if k != 'name':\n",
393 | " total_marks += v\n",
394 | " count += 1\n",
395 | " student['avg'] = total_marks/count\n"
396 | ]
397 | },
398 | {
399 | "cell_type": "code",
400 | "execution_count": 25,
401 | "metadata": {},
402 | "outputs": [],
403 | "source": [
404 | "calcMarksAvg(list_students)"
405 | ]
406 | },
407 | {
408 | "cell_type": "code",
409 | "execution_count": 26,
410 | "metadata": {},
411 | "outputs": [
412 | {
413 | "data": {
414 | "text/plain": [
415 | "[{'name': 'david', 'maths': 80, 'science': 75, 'english': 76, 'avg': 77.0},\n",
416 | " {'name': 'rohit',\n",
417 | " 'maths': 90,\n",
418 | " 'science': 85,\n",
419 | " 'english': 66,\n",
420 | " 'avg': 80.33333333333333},\n",
421 | " {'name': 'raj',\n",
422 | " 'maths': 40,\n",
423 | " 'science': 55,\n",
424 | " 'english': 56,\n",
425 | " 'avg': 50.333333333333336},\n",
426 | " {'name': 'yazhini',\n",
427 | " 'maths': 80,\n",
428 | " 'science': 88,\n",
429 | " 'english': 76,\n",
430 | " 'avg': 81.33333333333333}]"
431 | ]
432 | },
433 | "execution_count": 26,
434 | "metadata": {},
435 | "output_type": "execute_result"
436 | }
437 | ],
438 | "source": [
439 | "list_students"
440 | ]
441 | },
442 | {
443 | "cell_type": "code",
444 | "execution_count": 27,
445 | "metadata": {},
446 | "outputs": [
447 | {
448 | "name": "stdout",
449 | "output_type": "stream",
450 | "text": [
451 | "Help on built-in function max in module builtins:\n",
452 | "\n",
453 | "max(...)\n",
454 | " max(iterable, *[, default=obj, key=func]) -> value\n",
455 | " max(arg1, arg2, *args, *[, key=func]) -> value\n",
456 | " \n",
457 | " With a single iterable argument, return its biggest item. The\n",
458 | " default keyword-only argument specifies an object to return if\n",
459 | " the provided iterable is empty.\n",
460 | " With two or more arguments, return the largest argument.\n",
461 | "\n"
462 | ]
463 | }
464 | ],
465 | "source": [
466 | "help(max)"
467 | ]
468 | },
469 | {
470 | "cell_type": "code",
471 | "execution_count": 28,
472 | "metadata": {},
473 | "outputs": [],
474 | "source": [
475 | "def findTopper(list_students):\n",
476 | " def f(e):\n",
477 | " return e['avg']\n",
478 | "\n",
479 | " return max(list_students,key=f)"
480 | ]
481 | },
482 | {
483 | "cell_type": "code",
484 | "execution_count": 29,
485 | "metadata": {},
486 | "outputs": [],
487 | "source": [
488 | "l = [1,233,9]"
489 | ]
490 | },
491 | {
492 | "cell_type": "code",
493 | "execution_count": 30,
494 | "metadata": {},
495 | "outputs": [
496 | {
497 | "data": {
498 | "text/plain": [
499 | "233"
500 | ]
501 | },
502 | "execution_count": 30,
503 | "metadata": {},
504 | "output_type": "execute_result"
505 | }
506 | ],
507 | "source": [
508 | "max(l)"
509 | ]
510 | },
511 | {
512 | "cell_type": "code",
513 | "execution_count": 31,
514 | "metadata": {},
515 | "outputs": [
516 | {
517 | "data": {
518 | "text/plain": [
519 | "{'name': 'yazhini',\n",
520 | " 'maths': 80,\n",
521 | " 'science': 88,\n",
522 | " 'english': 76,\n",
523 | " 'avg': 81.33333333333333}"
524 | ]
525 | },
526 | "execution_count": 31,
527 | "metadata": {},
528 | "output_type": "execute_result"
529 | }
530 | ],
531 | "source": [
532 | "def f(e):\n",
533 | " return e['avg']\n",
534 | "max(list_students,key=f)\n"
535 | ]
536 | },
537 | {
538 | "cell_type": "code",
539 | "execution_count": 32,
540 | "metadata": {},
541 | "outputs": [],
542 | "source": [
543 | "topper = findTopper(list_students)"
544 | ]
545 | },
546 | {
547 | "cell_type": "code",
548 | "execution_count": 33,
549 | "metadata": {},
550 | "outputs": [
551 | {
552 | "data": {
553 | "text/plain": [
554 | "'yazhini'"
555 | ]
556 | },
557 | "execution_count": 33,
558 | "metadata": {},
559 | "output_type": "execute_result"
560 | }
561 | ],
562 | "source": [
563 | "topper['name']"
564 | ]
565 | },
566 | {
567 | "cell_type": "code",
568 | "execution_count": 34,
569 | "metadata": {},
570 | "outputs": [
571 | {
572 | "data": {
573 | "text/plain": [
574 | "[{'name': 'raj',\n",
575 | " 'maths': 40,\n",
576 | " 'science': 55,\n",
577 | " 'english': 56,\n",
578 | " 'avg': 50.333333333333336},\n",
579 | " {'name': 'david', 'maths': 80, 'science': 75, 'english': 76, 'avg': 77.0},\n",
580 | " {'name': 'rohit',\n",
581 | " 'maths': 90,\n",
582 | " 'science': 85,\n",
583 | " 'english': 66,\n",
584 | " 'avg': 80.33333333333333},\n",
585 | " {'name': 'yazhini',\n",
586 | " 'maths': 80,\n",
587 | " 'science': 88,\n",
588 | " 'english': 76,\n",
589 | " 'avg': 81.33333333333333}]"
590 | ]
591 | },
592 | "execution_count": 34,
593 | "metadata": {},
594 | "output_type": "execute_result"
595 | }
596 | ],
597 | "source": [
598 | "sorted(list_students,key=f)"
599 | ]
600 | },
601 | {
602 | "cell_type": "code",
603 | "execution_count": null,
604 | "metadata": {},
605 | "outputs": [],
606 | "source": []
607 | }
608 | ],
609 | "metadata": {
610 | "kernelspec": {
611 | "display_name": "Python 3",
612 | "language": "python",
613 | "name": "python3"
614 | },
615 | "language_info": {
616 | "codemirror_mode": {
617 | "name": "ipython",
618 | "version": 3
619 | },
620 | "file_extension": ".py",
621 | "mimetype": "text/x-python",
622 | "name": "python",
623 | "nbconvert_exporter": "python",
624 | "pygments_lexer": "ipython3",
625 | "version": "3.7.4"
626 | }
627 | },
628 | "nbformat": 4,
629 | "nbformat_minor": 2
630 | }
631 |
--------------------------------------------------------------------------------
/Session 12 - Problems.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "Reverse key value in a dictionary\n",
10 | "\n",
11 | "Input : { 'a':20, 'b':20, 'c':22 }\n",
12 | "\n",
13 | "Output : { 20 :['a','b'], 22:'c' }"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 1,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "db = { 'a':20, 'b':20, 'c':22 , 'd':20}"
23 | ]
24 | },
25 | {
26 | "cell_type": "code",
27 | "execution_count": 2,
28 | "metadata": {},
29 | "outputs": [
30 | {
31 | "data": {
32 | "text/plain": [
33 | "{'a': 20, 'b': 20, 'c': 22, 'd': 20}"
34 | ]
35 | },
36 | "execution_count": 2,
37 | "metadata": {},
38 | "output_type": "execute_result"
39 | }
40 | ],
41 | "source": [
42 | "db"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": 3,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "newdb = {}"
52 | ]
53 | },
54 | {
55 | "cell_type": "code",
56 | "execution_count": 4,
57 | "metadata": {},
58 | "outputs": [],
59 | "source": [
60 | "for k,v in db.items():\n",
61 | " #if v is appearing first time as a key\n",
62 | " if v not in newdb:\n",
63 | " newdb[v] = k\n",
64 | " #If v is appearing not first time as a key\n",
65 | " else:\n",
66 | " #If value is not yet a list, create one\n",
67 | " if not isinstance(newdb[v], list):\n",
68 | " temp = newdb[v]\n",
69 | " newdb[v] = [temp,k]\n",
70 | " #If value is a list, append k here\n",
71 | " else:\n",
72 | " newdb[v].append(k)"
73 | ]
74 | },
75 | {
76 | "cell_type": "code",
77 | "execution_count": 5,
78 | "metadata": {},
79 | "outputs": [
80 | {
81 | "data": {
82 | "text/plain": [
83 | "{20: ['a', 'b', 'd'], 22: 'c'}"
84 | ]
85 | },
86 | "execution_count": 5,
87 | "metadata": {},
88 | "output_type": "execute_result"
89 | }
90 | ],
91 | "source": [
92 | "newdb"
93 | ]
94 | },
95 | {
96 | "cell_type": "code",
97 | "execution_count": 6,
98 | "metadata": {},
99 | "outputs": [
100 | {
101 | "data": {
102 | "text/plain": [
103 | "list"
104 | ]
105 | },
106 | "execution_count": 6,
107 | "metadata": {},
108 | "output_type": "execute_result"
109 | }
110 | ],
111 | "source": [
112 | "\n",
113 | "type(newdb[20])\n"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": 7,
119 | "metadata": {},
120 | "outputs": [
121 | {
122 | "data": {
123 | "text/plain": [
124 | "True"
125 | ]
126 | },
127 | "execution_count": 7,
128 | "metadata": {},
129 | "output_type": "execute_result"
130 | }
131 | ],
132 | "source": [
133 | "isinstance(newdb[20], list)"
134 | ]
135 | },
136 | {
137 | "cell_type": "code",
138 | "execution_count": 8,
139 | "metadata": {},
140 | "outputs": [
141 | {
142 | "data": {
143 | "text/plain": [
144 | "True"
145 | ]
146 | },
147 | "execution_count": 8,
148 | "metadata": {},
149 | "output_type": "execute_result"
150 | }
151 | ],
152 | "source": [
153 | "isinstance({},dict)"
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": 9,
159 | "metadata": {},
160 | "outputs": [
161 | {
162 | "data": {
163 | "text/plain": [
164 | "True"
165 | ]
166 | },
167 | "execution_count": 9,
168 | "metadata": {},
169 | "output_type": "execute_result"
170 | }
171 | ],
172 | "source": [
173 | "isinstance('hello',str)"
174 | ]
175 | },
176 | {
177 | "cell_type": "code",
178 | "execution_count": 10,
179 | "metadata": {},
180 | "outputs": [],
181 | "source": [
182 | "data = [['abc',10], ['adf',15], ['ghi',9]]"
183 | ]
184 | },
185 | {
186 | "cell_type": "code",
187 | "execution_count": 11,
188 | "metadata": {},
189 | "outputs": [
190 | {
191 | "data": {
192 | "text/plain": [
193 | "[['abc', 10], ['adf', 15], ['ghi', 9]]"
194 | ]
195 | },
196 | "execution_count": 11,
197 | "metadata": {},
198 | "output_type": "execute_result"
199 | }
200 | ],
201 | "source": [
202 | "def f(e):\n",
203 | " return e[0]\n",
204 | "\n",
205 | "sorted(data, key=f)"
206 | ]
207 | },
208 | {
209 | "cell_type": "code",
210 | "execution_count": null,
211 | "metadata": {},
212 | "outputs": [],
213 | "source": []
214 | }
215 | ],
216 | "metadata": {
217 | "kernelspec": {
218 | "display_name": "Python 3",
219 | "language": "python",
220 | "name": "python3"
221 | },
222 | "language_info": {
223 | "codemirror_mode": {
224 | "name": "ipython",
225 | "version": 3
226 | },
227 | "file_extension": ".py",
228 | "mimetype": "text/x-python",
229 | "name": "python",
230 | "nbconvert_exporter": "python",
231 | "pygments_lexer": "ipython3",
232 | "version": "3.7.4"
233 | }
234 | },
235 | "nbformat": 4,
236 | "nbformat_minor": 2
237 | }
238 |
--------------------------------------------------------------------------------
/Session 18 - Map - Filter and Lambda.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "map,filter and lambda"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "map(fun obj,iterable datatype) #map is builtin func which takes a func object as 1st args and then iterable datatype"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 3,
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "name": "stdout",
28 | "output_type": "stream",
29 | "text": [
30 | "[100, 400, 900, 1600, 2500, 3600]\n"
31 | ]
32 | }
33 | ],
34 | "source": [
35 | "l = [10,20,30,40,50,60]\n",
36 | "l2 = [value * value for value in l]\n",
37 | "print(l2)"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": 4,
43 | "metadata": {},
44 | "outputs": [
45 | {
46 | "name": "stdout",
47 | "output_type": "stream",
48 | "text": [
49 | "[100, 400, 900, 1600, 2500, 3600]\n"
50 | ]
51 | }
52 | ],
53 | "source": [
54 | "def sqr(num1):\n",
55 | " return num1 * num1\n",
56 | "\n",
57 | "l = [10,20,30,40,50,60]\n",
58 | "r = map(sqr,l)\n",
59 | "print(list(r))"
60 | ]
61 | },
62 | {
63 | "cell_type": "code",
64 | "execution_count": 5,
65 | "metadata": {},
66 | "outputs": [
67 | {
68 | "name": "stdout",
69 | "output_type": "stream",
70 | "text": [
71 | "