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
136 changes: 111 additions & 25 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,31 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 58,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[2, 3, 4]"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def modify_list(lst, lmbda):\n",
" \"\"\"\n",
" Input: list and lambda expression\n",
" Output: the transformed list\n",
" \"\"\"\n",
" \n",
" \"\"\" \n",
" # your code here\n",
" "
" lambda_applied = [lmbda(x) for x in lst]\n",
" return lambda_applied\n",
"\n",
"modify_list([1, 2, 3], lmbda = lambda x: x + 1)"
]
},
{
Expand All @@ -46,11 +59,23 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.<lambda>(x)>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"# your code here\n",
"lambda x: x + 273.15"
]
},
{
Expand All @@ -62,13 +87,23 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]\n"
]
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# your code here"
"# your code here\n",
"temps_kelvin = list(map(lambda x: x + 273.15, temps))\n",
"print(temps_kelvin)"
]
},
{
Expand All @@ -82,11 +117,25 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 64,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"# your code here\n",
"mod = lambda x, y: 1 if x%y == 0 or y%x == 0 else 0\n",
"\n",
"mod(2, 4)"
]
},
{
Expand All @@ -100,18 +149,32 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 68,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.divisor.<locals>.<lambda>(c)>"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"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"
" # your code here\n",
" mod_v2 = lambda c: 1 if c%b == 0 or b%c == 0 else 0\n",
" return mod_v2\n",
"\n",
"divisor(5)"
]
},
{
Expand All @@ -123,11 +186,12 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 73,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"divisible5 = divisor(5)"
]
},
{
Expand All @@ -139,18 +203,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 72,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 74,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
]
Expand Down Expand Up @@ -269,7 +355,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down