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
231 changes: 208 additions & 23 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": 30,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -30,9 +30,34 @@
" Input: list and lambda expression\n",
" Output: the transformed list\n",
" \"\"\"\n",
" \n",
" \n",
" # your code here\n",
" "
" return [x for x in lst]\n",
"\n",
"list1 = [4,6,8,10]\n",
"\n",
"new_list = lambda x: x*10"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[4, 6, 8, 10]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"modify_list(list1, new_list)"
]
},
{
Expand All @@ -46,11 +71,33 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(4)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"\n",
"kelvin = lambda k : k + 273.15"
]
},
{
Expand All @@ -62,13 +109,32 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# your code here"
"# your code here\n",
"\n",
"convert = list(map(kelvin, temps))"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]\n"
]
}
],
"source": [
"print(convert)"
]
},
{
Expand All @@ -84,9 +150,23 @@
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"0\n"
]
}
],
"source": [
"# your code here"
"# your code here\n",
"\n",
"mod = lambda x, y : 1 if x % y == 0 else 0\n",
"\n",
"print(mod(8,2))\n",
"print(mod(2,8))"
]
},
{
Expand All @@ -111,7 +191,8 @@
" divisible by another number (to be passed later) and zero otherwise.\n",
" \"\"\"\n",
" \n",
" # your code here"
" # your code here\n",
" return lambda x: 1 if x % b == 0 else 0 "
]
},
{
Expand All @@ -123,11 +204,13 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"\n",
"divisible5 = divisor(5)"
]
},
{
Expand All @@ -139,18 +222,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(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)"
]
Expand Down Expand Up @@ -199,14 +304,38 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"list1 = ['Green', 'cheese', 'English', 'tomato']\n",
"list2 = ['eggs', 'cheese', 'cucumber', 'tomato']\n",
"\n",
"# your code here"
"# your code here\n",
"\n",
"x = lambda a, b: a + \" \" + b if a != b else a\n",
"\n",
"list3 = [x(i,z) for i,z in zip(list1, list2)]"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Green eggs', 'cheese', 'English cucumber', 'tomato']"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list3"
]
},
{
Expand All @@ -222,14 +351,41 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n",
"list2 = ['Lab', 'Homework', 'Essay', 'Module']\n",
"\n",
"# your code here"
"# your code here\n",
"\n",
"x = [i for i in zip(list1, list2)]\n",
"\n",
"sort = lambda x: x[1][0]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('Political Science', 'Essay'),\n",
" ('Computer Science', 'Homework'),\n",
" ('Engineering', 'Lab'),\n",
" ('Mathematics', 'Module')]"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(x, key = first_letter)"
]
},
{
Expand All @@ -243,14 +399,43 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n",
"\n",
"# your code here"
"# your code here\n",
"\n",
"d_sort = sorted(d.items(), key = lambda x: x[1])"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('Toyota', 1995), ('Honda', 1997), ('Audi', 2001), ('BMW', 2005)]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d_sort"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -269,9 +454,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}