Skip to content

Commit eda2f2f

Browse files
committed
updated
1 parent add12c7 commit eda2f2f

File tree

2 files changed

+151
-10
lines changed

2 files changed

+151
-10
lines changed

03-python-operators-conditional-statements.ipynb

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,44 @@
319319
},
320320
{
321321
"cell_type": "code",
322-
"execution_count": null,
322+
"execution_count": 1,
323323
"id": "0906ddc7",
324324
"metadata": {},
325-
"outputs": [],
325+
"outputs": [
326+
{
327+
"name": "stdout",
328+
"output_type": "stream",
329+
"text": [
330+
"number is odd\n",
331+
"number is even\n",
332+
"number is odd\n",
333+
"number is even\n",
334+
"number is odd\n",
335+
"number is even\n",
336+
"number is odd\n",
337+
"number is even\n",
338+
"number is odd\n",
339+
"number is even\n"
340+
]
341+
}
342+
],
326343
"source": [
327-
"#"
344+
"list=[11,12,13,14,15,16,17,18,19,20]\n",
345+
"for i in list:\n",
346+
" i=i%2\n",
347+
" if i==0:\n",
348+
" print(\"number is even\")\n",
349+
" else:\n",
350+
" print(\"number is odd\") "
328351
]
352+
},
353+
{
354+
"cell_type": "code",
355+
"execution_count": null,
356+
"id": "9d699bfb",
357+
"metadata": {},
358+
"outputs": [],
359+
"source": []
329360
}
330361
],
331362
"metadata": {

08-lambda-function.ipynb

Lines changed: 117 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,25 @@
3030
},
3131
{
3232
"cell_type": "code",
33-
"execution_count": 1,
33+
"execution_count": 12,
3434
"metadata": {},
3535
"outputs": [
3636
{
37-
"name": "stdout",
38-
"output_type": "stream",
39-
"text": [
40-
"[1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
37+
"ename": "TypeError",
38+
"evalue": "'list' object is not callable",
39+
"output_type": "error",
40+
"traceback": [
41+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
42+
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
43+
"\u001b[1;32md:\\Python\\python_practice\\08-lambda-function.ipynb Cell 3\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/d%3A/Python/python_practice/08-lambda-function.ipynb#W2sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m mylist \u001b[39m=\u001b[39m[\u001b[39m1\u001b[39m,\u001b[39m2\u001b[39m,\u001b[39m3\u001b[39m,\u001b[39m4\u001b[39m,\u001b[39m5\u001b[39m,\u001b[39m6\u001b[39m,\u001b[39m7\u001b[39m,\u001b[39m8\u001b[39m,\u001b[39m9\u001b[39m]\n\u001b[1;32m----> <a href='vscode-notebook-cell:/d%3A/Python/python_practice/08-lambda-function.ipynb#W2sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m even_list \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39;49m(\u001b[39mfilter\u001b[39;49m(\u001b[39mlambda\u001b[39;49;00m x:(x\u001b[39m%\u001b[39;49m\u001b[39m2\u001b[39;49m\u001b[39m==\u001b[39;49m\u001b[39m0\u001b[39;49m),mylist))\n\u001b[0;32m <a href='vscode-notebook-cell:/d%3A/Python/python_practice/08-lambda-function.ipynb#W2sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m \u001b[39mprint\u001b[39m(even_list)\n",
44+
"\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable"
4145
]
4246
}
4347
],
4448
"source": [
4549
"mylist =[1,2,3,4,5,6,7,8,9]\n",
4650
"even_list = list(filter(lambda x:(x%2==0),mylist))\n",
47-
"print(mylist)"
51+
"print(even_list)"
4852
]
4953
},
5054
{
@@ -210,7 +214,7 @@
210214
},
211215
{
212216
"cell_type": "code",
213-
"execution_count": 15,
217+
"execution_count": 4,
214218
"metadata": {},
215219
"outputs": [
216220
{
@@ -243,6 +247,112 @@
243247
"for items in list:\n",
244248
" print(items())"
245249
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": 3,
254+
"metadata": {},
255+
"outputs": [],
256+
"source": [
257+
"def square (a):\n",
258+
" print(a*a)\n",
259+
" square(5)\n",
260+
" print(square(5))"
261+
]
262+
},
263+
{
264+
"cell_type": "markdown",
265+
"metadata": {},
266+
"source": [
267+
"- mapping funtion\n",
268+
"syntax:map(function_name,iterable)"
269+
]
270+
},
271+
{
272+
"cell_type": "code",
273+
"execution_count": null,
274+
"metadata": {},
275+
"outputs": [],
276+
"source": [
277+
"def square (n):\n",
278+
" return n*n\n",
279+
" numbers =(1,2,3,4,5)\n",
280+
" result = map(square,numbers)\n",
281+
" print(list(result))"
282+
]
283+
},
284+
{
285+
"cell_type": "code",
286+
"execution_count": 19,
287+
"metadata": {},
288+
"outputs": [
289+
{
290+
"ename": "TypeError",
291+
"evalue": "'list' object is not callable",
292+
"output_type": "error",
293+
"traceback": [
294+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
295+
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
296+
"\u001b[1;32md:\\Python\\python_practice\\08-lambda-function.ipynb Cell 16\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/d%3A/Python/python_practice/08-lambda-function.ipynb#X21sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m mylist \u001b[39m=\u001b[39m[\u001b[39m\"\u001b[39m\u001b[39mindia\u001b[39m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39mberlin\u001b[39m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39mlondon\u001b[39m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39mtokyo\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[1;32m----> <a href='vscode-notebook-cell:/d%3A/Python/python_practice/08-lambda-function.ipynb#X21sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mlist\u001b[39;49m(\u001b[39mfilter\u001b[39;49m(\u001b[39mNone\u001b[39;49;00m,mylist)))\n",
297+
"\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable"
298+
]
299+
}
300+
],
301+
"source": [
302+
"\n",
303+
"mylist =[\"india\",\"\",\"berlin\",\"\",\"\",\"london\",\"tokyo\"]\n",
304+
"print(list(filter(None,mylist)))"
305+
]
306+
},
307+
{
308+
"cell_type": "code",
309+
"execution_count": 21,
310+
"metadata": {},
311+
"outputs": [
312+
{
313+
"name": "stdout",
314+
"output_type": "stream",
315+
"text": [
316+
"45\n"
317+
]
318+
}
319+
],
320+
"source": [
321+
"from functools import reduce\n",
322+
"mylist=[1,2,3,4,5,6,7,8,9]\n",
323+
"sum =reduce((lambda x,y:(x+y)),mylist)\n",
324+
"print(sum)"
325+
]
326+
},
327+
{
328+
"cell_type": "code",
329+
"execution_count": 23,
330+
"metadata": {},
331+
"outputs": [
332+
{
333+
"name": "stdout",
334+
"output_type": "stream",
335+
"text": [
336+
"sum is 45\n"
337+
]
338+
}
339+
],
340+
"source": [
341+
"from functools import reduce\n",
342+
"mylist=[1,2,3,4,5,6,7,8,9]\n",
343+
"sum =reduce((lambda x,y:(x+y)),mylist)\n",
344+
"if sum==45:\n",
345+
" print(\"sum is 45\")\n",
346+
"else:\n",
347+
" print(\"sum is 55\")\n"
348+
]
349+
},
350+
{
351+
"cell_type": "code",
352+
"execution_count": null,
353+
"metadata": {},
354+
"outputs": [],
355+
"source": []
246356
}
247357
],
248358
"metadata": {

0 commit comments

Comments
 (0)