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
257 changes: 226 additions & 31 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -30,9 +30,41 @@
" Input: list and lambda expression\n",
" Output: the transformed list\n",
" \"\"\"\n",
" i = 0\n",
" \n",
" # your code here\n",
" "
" while i < len(lst):\n",
" lst[i] = lmbda(lst[i])\n",
" i += 1"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"x = [1,2,3]\n",
"modify_list(x, lambda x: x*3)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[3, 6, 9]\n"
]
}
],
"source": [
"print(x)"
]
},
{
Expand All @@ -46,11 +78,23 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"celsius_to_kelvin = lambda x: x + 273.15"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"modify_list(temps, celsius_to_kelvin)"
]
},
{
Expand All @@ -62,13 +106,21 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 39,
"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"
"modify_list(temps, celsius_to_kelvin)\n",
"print(temps)"
]
},
{
Expand All @@ -82,11 +134,32 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"mod = lambda x, y: 1 if x % y == 0 or y % x == 0 else 0"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mod(4,2)"
]
},
{
Expand All @@ -100,7 +173,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 59,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -110,10 +183,35 @@
" 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",
" for i in range(2,b):\n",
" if mod(i,b) == 1:\n",
" return 1\n",
" \n",
" return 0\n",
"\n",
" # your code here"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisor(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -123,11 +221,21 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 64,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
}
],
"source": [
"# your code here"
"# your code here\n",
"divisible5 = divisor(5)\n",
"print(divisible5)"
]
},
{
Expand All @@ -139,20 +247,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 68,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
"divisor(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 69,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
"divisor(8)"
]
},
{
Expand Down Expand Up @@ -199,14 +329,29 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 70,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[('Green', 'eggs'),\n",
" ('cheese', 'cheese'),\n",
" ('English', 'cucumber'),\n",
" ('tomato', 'tomato')]"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list1 = ['Green', 'cheese', 'English', 'tomato']\n",
"list2 = ['eggs', 'cheese', 'cucumber', 'tomato']\n",
"\n",
"# your code here"
"# your code here\n",
"[x for x in zip(list1, list2)]"
]
},
{
Expand All @@ -222,14 +367,52 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 71,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[('Engineering', 'Lab'),\n",
" ('Computer Science', 'Homework'),\n",
" ('Political Science', 'Essay'),\n",
" ('Mathematics', 'Module')]"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n",
"list2 = ['Lab', 'Homework', 'Essay', 'Module']\n",
"\n",
"# your code here"
"# your code here\n",
"[x for x in zip(list1, list2)]"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('Political Science', 'Essay'),\n",
" ('Computer Science', 'Homework'),\n",
" ('Engineering', 'Lab'),\n",
" ('Mathematics', 'Module')]"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted([x for x in zip(list1, list2)], key = lambda x: x[1])"
]
},
{
Expand All @@ -243,13 +426,25 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 79,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[('Toyota', 1995), ('Honda', 1997), ('Audi', 2001), ('BMW', 2005)]"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n",
"\n",
"# your code here"
"# your code here\n",
"sorted(d.items(), key = lambda x: x[1])"
]
}
],
Expand All @@ -269,7 +464,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.8.6"
}
},
"nbformat": 4,
Expand Down