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
196 changes: 172 additions & 24 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,41 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# your code here\n"
"a = [1,2,3,4,5,6,7,8,9,10] \n",
"\n",
"b = lambda numb : 2\n",
"\n",
"c = []\n",
"\n",
"def modify_list(a_list,a_lambda):\n",
"\n",
" c = [a_lambda(numb) for numb in a_list] \n",
"\n",
" return c\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[2, 2, 2, 2, 2, 2, 2, 2, 2, 2]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"modify_list(a,b)"
]
},
{
Expand All @@ -56,7 +86,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"conversion = lambda c : c + 273.15 ## creating the lambda function\n"
]
},
{
Expand All @@ -70,11 +100,23 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"[conversion(temp) for temp in temps] ## applying to every element in temps and saving it in a list"
]
},
{
Expand All @@ -90,9 +132,23 @@
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"1\n",
"0\n"
]
}
],
"source": [
"# Your code here:\n"
"mod = lambda x,y: 1 if (x % y) == 0 or (y % x) == 0 else 0\n",
"\n",
"print(mod(2,10))\n",
"print(mod(10,2))\n",
"print(mod(3,2))"
]
},
{
Expand All @@ -115,7 +171,10 @@
" input: a number\n",
" output: a function that returns 1 if the number is divisible by another number (to be passed later) and zero otherwise\n",
" \"\"\"\n",
" # Your code here:\n"
" \n",
"\n",
"\n",
" return lambda z: mod(a,z) ## using mod inside another lambda function. \n"
]
},
{
Expand All @@ -131,7 +190,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"divisible5 = divisor(5) "
]
},
{
Expand All @@ -143,18 +202,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
]
Expand All @@ -174,7 +255,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -186,7 +267,7 @@
" ('tomato', 'tomato')]"
]
},
"execution_count": 1,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -209,17 +290,42 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[False, False, True, False]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list1 = [1,2,4,4]\n",
"list2 = [2,3,3,5]\n",
"## Zip the lists together \n",
"\n",
"zipped = zip(list1,list2)\n",
"\n",
"## Print the zipped list \n",
"\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n"
"a = (list(zipped))\n",
"\n",
"\n",
"lambda x : x[0] > x[1] ## condition that we use to compare list 1 to list 2\n",
"\n",
"\n",
"[(lambda x : x[0] > x[1])(x) for x in a] ## jose did this \n",
"\n",
"# compares the first and second index of the tuple. The tuple is passed in as (x) at the end of the lambda, then iterated through in a list comp.\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
Expand All @@ -242,14 +348,51 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 40,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('Engineering', 'Lab'), ('Computer Science', 'Homework'), ('Political Science', 'Essay'), ('Mathematics', 'Module')]\n"
]
}
],
"source": [
"list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n",
"list2 = ['Lab', 'Homework', 'Essay', 'Module']\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"\n",
"zipped = list(zip(list1,list2))\n",
"\n",
"print(zipped)\n",
"\n",
"## MISSING\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[True, True, False, False]"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[(lambda x : x[1][0] > x[0][0])(x) for x in zipped]\n",
"\n",
"## REVIEW"
]
},
{
Expand All @@ -263,7 +406,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -282,7 +425,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3.9.7 ('base')",
"language": "python",
"name": "python3"
},
Expand All @@ -296,7 +439,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.7"
},
"vscode": {
"interpreter": {
"hash": "76912bee8247cc6eaca7ddd452c9bea798971fb28a8d3d491f13d9f038893d1f"
}
}
},
"nbformat": 4,
Expand Down