Skip to content

Commit 69505fd

Browse files
change header
1 parent d69034b commit 69505fd

File tree

2 files changed

+14
-218
lines changed

2 files changed

+14
-218
lines changed

Chapter6/alternative_approach.ipynb

Lines changed: 7 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,7 @@
260260
},
261261
{
262262
"data": {
263-
"application/javascript": [
264-
"\n",
265-
" setTimeout(function() {\n",
266-
" var nbb_cell_id = 12;\n",
267-
" var nbb_unformatted_code = \"from box import Box\\n\\nfood_box = Box({\\\"food\\\": {\\\"fruit\\\": {\\\"name\\\": \\\"apple\\\", \\\"flavor\\\": \\\"sweet\\\"}}})\\nprint(food_box)\";\n",
268-
" var nbb_formatted_code = \"from box import Box\\n\\nfood_box = Box({\\\"food\\\": {\\\"fruit\\\": {\\\"name\\\": \\\"apple\\\", \\\"flavor\\\": \\\"sweet\\\"}}})\\nprint(food_box)\";\n",
269-
" var nbb_cells = Jupyter.notebook.get_cells();\n",
270-
" for (var i = 0; i < nbb_cells.length; ++i) {\n",
271-
" if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
272-
" if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
273-
" nbb_cells[i].set_text(nbb_formatted_code);\n",
274-
" }\n",
275-
" break;\n",
276-
" }\n",
277-
" }\n",
278-
" }, 500);\n",
279-
" "
280-
],
263+
"application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 12;\n var nbb_unformatted_code = \"from box import Box\\n\\nfood_box = Box({\\\"food\\\": {\\\"fruit\\\": {\\\"name\\\": \\\"apple\\\", \\\"flavor\\\": \\\"sweet\\\"}}})\\nprint(food_box)\";\n var nbb_formatted_code = \"from box import Box\\n\\nfood_box = Box({\\\"food\\\": {\\\"fruit\\\": {\\\"name\\\": \\\"apple\\\", \\\"flavor\\\": \\\"sweet\\\"}}})\\nprint(food_box)\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ",
281264
"text/plain": [
282265
"<IPython.core.display.Javascript object>"
283266
]
@@ -313,24 +296,7 @@
313296
},
314297
{
315298
"data": {
316-
"application/javascript": [
317-
"\n",
318-
" setTimeout(function() {\n",
319-
" var nbb_cell_id = 13;\n",
320-
" var nbb_unformatted_code = \"print(food_box.food.fruit.name)\";\n",
321-
" var nbb_formatted_code = \"print(food_box.food.fruit.name)\";\n",
322-
" var nbb_cells = Jupyter.notebook.get_cells();\n",
323-
" for (var i = 0; i < nbb_cells.length; ++i) {\n",
324-
" if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
325-
" if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
326-
" nbb_cells[i].set_text(nbb_formatted_code);\n",
327-
" }\n",
328-
" break;\n",
329-
" }\n",
330-
" }\n",
331-
" }, 500);\n",
332-
" "
333-
],
299+
"application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 13;\n var nbb_unformatted_code = \"print(food_box.food.fruit.name)\";\n var nbb_formatted_code = \"print(food_box.food.fruit.name)\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ",
334300
"text/plain": [
335301
"<IPython.core.display.Javascript object>"
336302
]
@@ -404,24 +370,7 @@
404370
},
405371
{
406372
"data": {
407-
"application/javascript": [
408-
"\n",
409-
" setTimeout(function() {\n",
410-
" var nbb_cell_id = 15;\n",
411-
" var nbb_unformatted_code = \"from time import time, sleep\\n\\n\\ndef time_func_complex(func):\\n def wrapper(*args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n\\n return wrapper\\n\\n\\n@time_func_complex\\ndef test_func_complex():\\n sleep(1)\\n\\n\\ntest_func_complex()\";\n",
412-
" var nbb_formatted_code = \"from time import time, sleep\\n\\n\\ndef time_func_complex(func):\\n def wrapper(*args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n\\n return wrapper\\n\\n\\n@time_func_complex\\ndef test_func_complex():\\n sleep(1)\\n\\n\\ntest_func_complex()\";\n",
413-
" var nbb_cells = Jupyter.notebook.get_cells();\n",
414-
" for (var i = 0; i < nbb_cells.length; ++i) {\n",
415-
" if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
416-
" if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
417-
" nbb_cells[i].set_text(nbb_formatted_code);\n",
418-
" }\n",
419-
" break;\n",
420-
" }\n",
421-
" }\n",
422-
" }, 500);\n",
423-
" "
424-
],
373+
"application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 15;\n var nbb_unformatted_code = \"from time import time, sleep\\n\\n\\ndef time_func_complex(func):\\n def wrapper(*args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n\\n return wrapper\\n\\n\\n@time_func_complex\\ndef test_func_complex():\\n sleep(1)\\n\\n\\ntest_func_complex()\";\n var nbb_formatted_code = \"from time import time, sleep\\n\\n\\ndef time_func_complex(func):\\n def wrapper(*args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n\\n return wrapper\\n\\n\\n@time_func_complex\\ndef test_func_complex():\\n sleep(1)\\n\\n\\ntest_func_complex()\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ",
425374
"text/plain": [
426375
"<IPython.core.display.Javascript object>"
427376
]
@@ -483,24 +432,7 @@
483432
},
484433
{
485434
"data": {
486-
"application/javascript": [
487-
"\n",
488-
" setTimeout(function() {\n",
489-
" var nbb_cell_id = 17;\n",
490-
" var nbb_unformatted_code = \"from decorator import decorator\\n\\n@decorator\\ndef time_func_simple(func, *args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n \\n@time_func_simple \\ndef test_func_simple():\\n sleep(1)\\n\\ntest_func()\";\n",
491-
" var nbb_formatted_code = \"from decorator import decorator\\n\\n\\n@decorator\\ndef time_func_simple(func, *args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n\\n\\n@time_func_simple\\ndef test_func_simple():\\n sleep(1)\\n\\n\\ntest_func()\";\n",
492-
" var nbb_cells = Jupyter.notebook.get_cells();\n",
493-
" for (var i = 0; i < nbb_cells.length; ++i) {\n",
494-
" if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
495-
" if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
496-
" nbb_cells[i].set_text(nbb_formatted_code);\n",
497-
" }\n",
498-
" break;\n",
499-
" }\n",
500-
" }\n",
501-
" }, 500);\n",
502-
" "
503-
],
435+
"application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 17;\n var nbb_unformatted_code = \"from decorator import decorator\\n\\n@decorator\\ndef time_func_simple(func, *args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n \\n@time_func_simple \\ndef test_func_simple():\\n sleep(1)\\n\\ntest_func()\";\n var nbb_formatted_code = \"from decorator import decorator\\n\\n\\n@decorator\\ndef time_func_simple(func, *args, **kwargs):\\n start_time = time()\\n func(*args, **kwargs)\\n end_time = time()\\n print(\\n f\\\"\\\"\\\"It takes {round(end_time - start_time, 3)} seconds to execute the function\\\"\\\"\\\"\\n )\\n\\n\\n@time_func_simple\\ndef test_func_simple():\\n sleep(1)\\n\\n\\ntest_func()\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ",
504436
"text/plain": [
505437
"<IPython.core.display.Javascript object>"
506438
]
@@ -1259,24 +1191,7 @@
12591191
},
12601192
{
12611193
"data": {
1262-
"application/javascript": [
1263-
"\n",
1264-
" setTimeout(function() {\n",
1265-
" var nbb_cell_id = 33;\n",
1266-
" var nbb_unformatted_code = \"# find the difference between two dictionaries\\nresult = diff(user1, user2)\\nlist(result)\";\n",
1267-
" var nbb_formatted_code = \"# find the difference between two dictionaries\\nresult = diff(user1, user2)\\nlist(result)\";\n",
1268-
" var nbb_cells = Jupyter.notebook.get_cells();\n",
1269-
" for (var i = 0; i < nbb_cells.length; ++i) {\n",
1270-
" if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
1271-
" if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
1272-
" nbb_cells[i].set_text(nbb_formatted_code);\n",
1273-
" }\n",
1274-
" break;\n",
1275-
" }\n",
1276-
" }\n",
1277-
" }, 500);\n",
1278-
" "
1279-
],
1194+
"application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 33;\n var nbb_unformatted_code = \"# find the difference between two dictionaries\\nresult = diff(user1, user2)\\nlist(result)\";\n var nbb_formatted_code = \"# find the difference between two dictionaries\\nresult = diff(user1, user2)\\nlist(result)\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ",
12801195
"text/plain": [
12811196
"<IPython.core.display.Javascript object>"
12821197
]
@@ -1315,24 +1230,7 @@
13151230
},
13161231
{
13171232
"data": {
1318-
"application/javascript": [
1319-
"\n",
1320-
" setTimeout(function() {\n",
1321-
" var nbb_cell_id = 34;\n",
1322-
" var nbb_unformatted_code = \"# swap the diff result\\nresult = diff(user1, user2)\\nswapped = swap(result)\\nlist(swapped)\";\n",
1323-
" var nbb_formatted_code = \"# swap the diff result\\nresult = diff(user1, user2)\\nswapped = swap(result)\\nlist(swapped)\";\n",
1324-
" var nbb_cells = Jupyter.notebook.get_cells();\n",
1325-
" for (var i = 0; i < nbb_cells.length; ++i) {\n",
1326-
" if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n",
1327-
" if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n",
1328-
" nbb_cells[i].set_text(nbb_formatted_code);\n",
1329-
" }\n",
1330-
" break;\n",
1331-
" }\n",
1332-
" }\n",
1333-
" }, 500);\n",
1334-
" "
1335-
],
1233+
"application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 34;\n var nbb_unformatted_code = \"# swap the diff result\\nresult = diff(user1, user2)\\nswapped = swap(result)\\nlist(swapped)\";\n var nbb_formatted_code = \"# swap the diff result\\nresult = diff(user1, user2)\\nswapped = swap(result)\\nlist(swapped)\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ",
13361234
"text/plain": [
13371235
"<IPython.core.display.Javascript object>"
13381236
]
@@ -2110,7 +2008,7 @@
21102008
"celltoolbar": "Tags",
21112009
"hide_input": false,
21122010
"kernelspec": {
2113-
"display_name": "Python 3 (ipykernel)",
2011+
"display_name": "venv",
21142012
"language": "python",
21152013
"name": "python3"
21162014
},

0 commit comments

Comments
 (0)