Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 84 additions & 34 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def modify_list(lst, lmbda):\n",
" \"\"\"\n",
" Input: list and lambda expression\n",
" Output: the transformed list\n",
" \"\"\"\n",
" \n",
" # your code here\n",
" "
" i = 0\n",
" while i < len(lst):\n",
" lst[i] = lmbda(lst[i])\n",
" i += 1"
]
},
{
Expand All @@ -46,11 +43,22 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.<lambda>(x)>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"lambda x : x + 273.15"
]
},
{
Expand All @@ -62,13 +70,25 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# your code here"
"lambda c, i: c + i\n",
"list(map(lambda c : c + 273.15, temps))"
]
},
{
Expand All @@ -82,11 +102,12 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"numbers = [15, 3]\n",
"mod = lambda c, y: '1'if c%y == 0 else \"0\""
]
},
{
Expand All @@ -100,18 +121,12 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def divisor(b):\n",
" \"\"\"\n",
" Input: a number\n",
" Output: a function that returns 1 if the number is \n",
" divisible by another number (to be passed later) and zero otherwise.\n",
" \"\"\"\n",
" \n",
" # your code here"
"def divisor(c):\n",
" return mod(c, 5)"
]
},
{
Expand All @@ -123,11 +138,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"divisible5 = divisor(5)"
]
},
{
Expand All @@ -139,20 +154,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'1'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
"divisor(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'0'"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
"divisor(8)"
]
},
{
Expand Down Expand Up @@ -269,7 +306,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.8.6"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down