Skip to content

Commit 627fbda

Browse files
committed
updated
1 parent ec55550 commit 627fbda

File tree

9 files changed

+288
-5
lines changed

9 files changed

+288
-5
lines changed
File renamed without changes.
Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
{
3333
"cell_type": "code",
34-
"execution_count": null,
34+
"execution_count": 1,
3535
"metadata": {
3636
"id": "0hI4XlV3OloO"
3737
},
@@ -45,14 +45,13 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": null,
48+
"execution_count": 2,
4949
"metadata": {
5050
"id": "Q2WSo0dQOwk3"
5151
},
5252
"outputs": [],
5353
"source": [
5454
"# A simple Python function\n",
55-
" \n",
5655
"def fun():\n",
5756
" print(\"Welcome to GFG\")"
5857
]
@@ -77,7 +76,7 @@
7776
},
7877
{
7978
"cell_type": "code",
80-
"execution_count": null,
79+
"execution_count": 3,
8180
"metadata": {
8281
"colab": {
8382
"base_uri": "https://localhost:8080/"
@@ -698,6 +697,107 @@
698697
"# Driver's code\n",
699698
"f1()"
700699
]
700+
},
701+
{
702+
"cell_type": "markdown",
703+
"metadata": {},
704+
"source": [
705+
"# Lambda Fucntion"
706+
]
707+
},
708+
{
709+
"cell_type": "code",
710+
"execution_count": 6,
711+
"metadata": {},
712+
"outputs": [
713+
{
714+
"name": "stdout",
715+
"output_type": "stream",
716+
"text": [
717+
"Addition of numbers are 11\n",
718+
"Subtraction of numbers are 1\n"
719+
]
720+
}
721+
],
722+
"source": [
723+
"subtract=lambda a,b:a-b\n",
724+
"addition=lambda a,b:a+b\n",
725+
"print(\"Addition of numbers are \",addition(6,5))\n",
726+
"print(\"Subtraction of numbers are \",subtract(6,5))"
727+
]
728+
},
729+
{
730+
"cell_type": "code",
731+
"execution_count": 7,
732+
"metadata": {},
733+
"outputs": [
734+
{
735+
"name": "stdout",
736+
"output_type": "stream",
737+
"text": [
738+
"True\n"
739+
]
740+
}
741+
],
742+
"source": [
743+
"##function for even or odd identification \n",
744+
"def even(num):\n",
745+
" if num%2==0:\n",
746+
" print('True')\n",
747+
"even(12)"
748+
]
749+
},
750+
{
751+
"cell_type": "code",
752+
"execution_count": 8,
753+
"metadata": {},
754+
"outputs": [
755+
{
756+
"data": {
757+
"text/plain": [
758+
"True"
759+
]
760+
},
761+
"execution_count": 8,
762+
"metadata": {},
763+
"output_type": "execute_result"
764+
}
765+
],
766+
"source": [
767+
"#lambda experession for above function \n",
768+
"even_func=lambda num:num%2==0\n",
769+
"even_func(12)"
770+
]
771+
},
772+
{
773+
"cell_type": "code",
774+
"execution_count": 10,
775+
"metadata": {},
776+
"outputs": [
777+
{
778+
"name": "stdout",
779+
"output_type": "stream",
780+
"text": [
781+
"square of number is 4\n",
782+
"Square of all numbers [1, 4, 9, 16, 25, 36]\n"
783+
]
784+
}
785+
],
786+
"source": [
787+
"numbers=[1,2,3,4,5,6]\n",
788+
"\n",
789+
"square=lambda x:x**2\n",
790+
"print(\"square of number is \",square(2))\n",
791+
"\n",
792+
"print(\"Square of all numbers\",list(map(lambda x:x**2,numbers)))"
793+
]
794+
},
795+
{
796+
"cell_type": "code",
797+
"execution_count": null,
798+
"metadata": {},
799+
"outputs": [],
800+
"source": []
701801
}
702802
],
703803
"metadata": {
@@ -710,7 +810,16 @@
710810
"name": "python3"
711811
},
712812
"language_info": {
713-
"name": "python"
813+
"codemirror_mode": {
814+
"name": "ipython",
815+
"version": 3
816+
},
817+
"file_extension": ".py",
818+
"mimetype": "text/x-python",
819+
"name": "python",
820+
"nbconvert_exporter": "python",
821+
"pygments_lexer": "ipython3",
822+
"version": "3.10.0"
714823
}
715824
},
716825
"nbformat": 4,
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# MAP Function"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"name": "stdout",
17+
"output_type": "stream",
18+
"text": [
19+
"4\n"
20+
]
21+
}
22+
],
23+
"source": [
24+
"# MAP function help to make lambda function iteratable , like if we use simple lambda it will perfrom work on single entery\n",
25+
"# For multiple entery we use the map function \n",
26+
"\n",
27+
"\n",
28+
"square=lambda x:x**2\n",
29+
"print(square(2))"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 2,
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"data": {
39+
"text/plain": [
40+
"[100, 225, 400]"
41+
]
42+
},
43+
"execution_count": 2,
44+
"metadata": {},
45+
"output_type": "execute_result"
46+
}
47+
],
48+
"source": [
49+
"numbers=[10,15,20]\n",
50+
"\n",
51+
"list(map(square,numbers))"
52+
]
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"# Filter Function"
59+
]
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {},
64+
"source": [
65+
"The filter() function constructs an iterator from elements of an iterable for which a function returns true. It is used to filter out items from a list (or any other iterable) based on a condition."
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 1,
71+
"metadata": {},
72+
"outputs": [
73+
{
74+
"data": {
75+
"text/plain": [
76+
"True"
77+
]
78+
},
79+
"execution_count": 1,
80+
"metadata": {},
81+
"output_type": "execute_result"
82+
}
83+
],
84+
"source": [
85+
"def even(num):\n",
86+
" if num%2==0:\n",
87+
" return True\n",
88+
" \n",
89+
"even(10)"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": 5,
95+
"metadata": {},
96+
"outputs": [
97+
{
98+
"data": {
99+
"text/plain": [
100+
"[2, 4, 6, 8]"
101+
]
102+
},
103+
"execution_count": 5,
104+
"metadata": {},
105+
"output_type": "execute_result"
106+
}
107+
],
108+
"source": [
109+
"num=[1,2,3,4,5,6,7,8,9]\n",
110+
"\n",
111+
"list(filter(even,num))"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 6,
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"[6, 7, 8, 9]\n"
124+
]
125+
}
126+
],
127+
"source": [
128+
"## filter with a Lambda Function\n",
129+
"greater_than_five=list(filter(lambda x:x>5,num))\n",
130+
"print(greater_than_five)"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": 7,
136+
"metadata": {},
137+
"outputs": [
138+
{
139+
"name": "stdout",
140+
"output_type": "stream",
141+
"text": [
142+
"[6, 8]\n"
143+
]
144+
}
145+
],
146+
"source": [
147+
"## Filter with a lambda function and multiple conditions\n",
148+
"even_and_greater_than_five=list(filter(lambda x:x>5 and x%2==0,num))\n",
149+
"print(even_and_greater_than_five)"
150+
]
151+
}
152+
],
153+
"metadata": {
154+
"kernelspec": {
155+
"display_name": "Python 3",
156+
"language": "python",
157+
"name": "python3"
158+
},
159+
"language_info": {
160+
"codemirror_mode": {
161+
"name": "ipython",
162+
"version": 3
163+
},
164+
"file_extension": ".py",
165+
"mimetype": "text/x-python",
166+
"name": "python",
167+
"nbconvert_exporter": "python",
168+
"pygments_lexer": "ipython3",
169+
"version": "3.10.0"
170+
}
171+
},
172+
"nbformat": 4,
173+
"nbformat_minor": 2
174+
}

0 commit comments

Comments
 (0)