Skip to content

Commit 946e8b1

Browse files
committed
rewrite code to make cleaner
1 parent 4d984ba commit 946e8b1

File tree

1 file changed

+17
-60
lines changed

1 file changed

+17
-60
lines changed

1_Basics/17_Lambda.ipynb

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
{
4141
"cell_type": "code",
42-
"execution_count": 2,
42+
"execution_count": 1,
4343
"metadata": {},
4444
"outputs": [],
4545
"source": [
@@ -49,7 +49,7 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 4,
52+
"execution_count": 2,
5353
"metadata": {},
5454
"outputs": [
5555
{
@@ -58,7 +58,7 @@
5858
"8"
5959
]
6060
},
61-
"execution_count": 4,
61+
"execution_count": 2,
6262
"metadata": {},
6363
"output_type": "execute_result"
6464
}
@@ -89,7 +89,7 @@
8989
},
9090
{
9191
"cell_type": "code",
92-
"execution_count": 2,
92+
"execution_count": 3,
9393
"metadata": {},
9494
"outputs": [
9595
{
@@ -103,7 +103,7 @@
103103
" 825000.0000000001]"
104104
]
105105
},
106-
"execution_count": 2,
106+
"execution_count": 3,
107107
"metadata": {},
108108
"output_type": "execute_result"
109109
}
@@ -120,52 +120,9 @@
120120
"total_salary_list"
121121
]
122122
},
123-
{
124-
"cell_type": "markdown",
125-
"metadata": {},
126-
"source": [
127-
"BUT this code can actually be simplified to include a lambda function\n",
128-
"\n",
129-
"Shortening this to 1 line of code"
130-
]
131-
},
132-
{
133-
"cell_type": "code",
134-
"execution_count": 3,
135-
"metadata": {},
136-
"outputs": [
137-
{
138-
"data": {
139-
"text/plain": [
140-
"[110000.00000000001,\n",
141-
" 220000.00000000003,\n",
142-
" 165000.0,\n",
143-
" 132000.0,\n",
144-
" 88000.0,\n",
145-
" 825000.0000000001]"
146-
]
147-
},
148-
"execution_count": 3,
149-
"metadata": {},
150-
"output_type": "execute_result"
151-
}
152-
],
153-
"source": [
154-
"total_salary_list = [(lambda salary: salary * (1.1))(salary) for salary in salary_list]\n",
155-
"\n",
156-
"total_salary_list"
157-
]
158-
},
159-
{
160-
"cell_type": "markdown",
161-
"metadata": {},
162-
"source": [
163-
"Rewriting this to show that the salary variables are different"
164-
]
165-
},
166123
{
167124
"cell_type": "code",
168-
"execution_count": 3,
125+
"execution_count": 4,
169126
"metadata": {},
170127
"outputs": [
171128
{
@@ -179,13 +136,13 @@
179136
" 825000.0000000001]"
180137
]
181138
},
182-
"execution_count": 3,
139+
"execution_count": 4,
183140
"metadata": {},
184141
"output_type": "execute_result"
185142
}
186143
],
187144
"source": [
188-
"total_salary_list = [(lambda salary: salary * (1.1))(item) for item in salary_list]\n",
145+
"total_salary_list = [(lambda x: x * (1.1))(salary) for salary in salary_list]\n",
189146
"\n",
190147
"total_salary_list"
191148
]
@@ -201,7 +158,7 @@
201158
},
202159
{
203160
"cell_type": "code",
204-
"execution_count": 4,
161+
"execution_count": 5,
205162
"metadata": {},
206163
"outputs": [
207164
{
@@ -215,13 +172,13 @@
215172
" 825000.0000000001]"
216173
]
217174
},
218-
"execution_count": 4,
175+
"execution_count": 5,
219176
"metadata": {},
220177
"output_type": "execute_result"
221178
}
222179
],
223180
"source": [
224-
"total_salary_list = [item * 1.1 for item in salary_list]\n",
181+
"total_salary_list = [salary * 1.1 for salary in salary_list]\n",
225182
"\n",
226183
"total_salary_list"
227184
]
@@ -239,7 +196,7 @@
239196
},
240197
{
241198
"cell_type": "code",
242-
"execution_count": 25,
199+
"execution_count": 6,
243200
"metadata": {},
244201
"outputs": [],
245202
"source": [
@@ -261,7 +218,7 @@
261218
},
262219
{
263220
"cell_type": "code",
264-
"execution_count": 27,
221+
"execution_count": 7,
265222
"metadata": {},
266223
"outputs": [
267224
{
@@ -293,7 +250,7 @@
293250
" | ----------------------------------------------------------------------\n",
294251
" | Static methods defined here:\n",
295252
" | \n",
296-
" | __new__(*args, **kwargs) from builtins.type\n",
253+
" | __new__(*args, **kwargs)\n",
297254
" | Create and return a new object. See help(type) for accurate signature.\n",
298255
"\n"
299256
]
@@ -319,7 +276,7 @@
319276
},
320277
{
321278
"cell_type": "code",
322-
"execution_count": 28,
279+
"execution_count": 8,
323280
"metadata": {},
324281
"outputs": [
325282
{
@@ -336,7 +293,7 @@
336293
" 'remote': True}]"
337294
]
338295
},
339-
"execution_count": 28,
296+
"execution_count": 8,
340297
"metadata": {},
341298
"output_type": "execute_result"
342299
}
@@ -356,7 +313,7 @@
356313
},
357314
{
358315
"cell_type": "code",
359-
"execution_count": 26,
316+
"execution_count": 9,
360317
"metadata": {},
361318
"outputs": [
362319
{

0 commit comments

Comments
 (0)