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
155 changes: 128 additions & 27 deletions your-code/main.ipynb → your-code/Lab_main_Matheus_Freire.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,31 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here\n"
"my_list = [0,1,2,3,4,5,6,7,8,9] \n",
"\n",
"my_lambda = lambda x: x +2 \n",
"\n",
"new_list = [] \n",
"\n",
"def empty_list(my_input_list, lambda_expression):\n",
" for element in my_input_list:\n",
" new_list.append(lambda_expression(element))\n",
"\n",
"empty_list(my_list, my_lambda)\n",
"new_list\n"
]
},
{
Expand All @@ -52,11 +74,11 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"celsius_to_kelvin = lambda x : x + 273.15\n"
]
},
{
Expand All @@ -68,13 +90,26 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"285.15\n",
"296.15\n",
"311.15\n",
"218.14999999999998\n",
"297.15\n"
]
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# Your code here:\n"
"for temp in temps:\n",
" print(str((celsius_to_kelvin)(temp)))\n"
]
},
{
Expand All @@ -88,11 +123,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"mod = lambda x, y : 1 if x % y == 0 else 0\n"
]
},
{
Expand All @@ -106,7 +141,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -115,7 +150,7 @@
" 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"
" return lambda y: mod(y, a)\n"
]
},
{
Expand All @@ -127,11 +162,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"divisible5 = divisor(5)\n"
]
},
{
Expand All @@ -143,18 +178,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 @@ -209,17 +266,36 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(1, 2), (2, 3), (4, 3), (4, 5)]\n"
]
},
{
"data": {
"text/plain": [
"[False, False, True, False]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list1 = [1,2,4,4]\n",
"list2 = [2,3,3,5]\n",
"## Zip the lists together \n",
"\n",
"zip_lists = list(zip(list1, list2))\n",
"## Print the zipped list \n",
"\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n"
"print(zip_lists)\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n",
"[(lambda x, y: x > y) (list1[i], list2[i]) for i in range(len(list1))]"
]
},
{
Expand All @@ -242,14 +318,39 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('Engineering', 'Lab'), ('Computer Science', 'Homework'), ('Political Science', 'Essay'), ('Mathematics', 'Module')]\n"
]
},
{
"data": {
"text/plain": [
"[('Political Science', 'Essay'),\n",
" ('Computer Science', 'Homework'),\n",
" ('Engineering', 'Lab'),\n",
" ('Mathematics', 'Module')]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n",
"list2 = ['Lab', 'Homework', 'Essay', 'Module']\n",
"\n",
"# Your code here:\n"
"zip_lists = list(zip(list1, list2))\n",
"print(zip_lists)\n",
"\n",
"new_zip = sorted(zip_lists, key = lambda x: x[1])\n",
"new_zip\n"
]
},
{
Expand Down Expand Up @@ -282,7 +383,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -296,7 +397,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down