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
216 changes: 163 additions & 53 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,31 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n"
]
}
],
"source": [
"# your code here\n"
"list = [1,2,3,4,5,6,7,8,9,10]\n",
"simple_lambda = lambda x : x + 2\n",
"list4 =[]\n",
"\n",
"def new_list (list, fun):\n",
" for x in list:\n",
" list4.append(fun(x))\n",
"\n",
"new_list(list,simple_lambda)\n",
"\n",
"print(list4)\n",
" \n",
" "
]
},
{
Expand All @@ -52,11 +72,12 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"\n",
"celsius_to_kelvin = lambda x :x + 273,15\n"
]
},
{
Expand All @@ -68,13 +89,38 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 47,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]\n"
]
}
],
"source": [
"celsius_to_kelvin = lambda x: x + 273.15\n",
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# Your code here:\n"
"new_list = [celsius_to_kelvin(x) for x in temps]\n",
"print(new_list)\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"#(lambda x: x+273,15)\n",
"\n",
"#[x for x in temps if (lambda x : x *273,15)]\n",
"\n",
"#temps(lambda x : x+273,15 [12,23,38,-55,24])\n"
]
},
{
Expand All @@ -88,11 +134,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"mod = lambda x,y: 1 if x%y == 0 or y%x ==0 else 0\n"
]
},
{
Expand All @@ -106,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -115,7 +161,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"
"return_mod = lambda x : 1 if x % a == 0 else 0 \n",
"\n",
"\n",
"\n"
]
},
{
Expand All @@ -127,11 +176,30 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 80,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<function divisor.<locals>.<lambda> at 0x000001F394B6FB00>\n",
"1\n"
]
}
],
"source": [
"# Your code here:\n"
"def divisor(a):\n",
" return lambda x: 1 if x % a == 0 else 0\n",
"\n",
"\n",
"print(divisor(5))\n",
"\n",
"\n",
"divisible5 = divisor(5)\n",
"\n",
"\n",
"print(divisible5(5)) \n"
]
},
{
Expand All @@ -143,20 +211,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 81,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 81,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
"divisible5(10) # sim é divisivel "
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 82,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 82,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
"divisible5(8) #nao nem é"
]
},
{
Expand All @@ -174,28 +264,24 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 89,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('Green', 'eggs'),\n",
" ('cheese', 'cheese'),\n",
" ('English', 'cucumber'),\n",
" ('tomato', 'tomato')]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"['Green eggs', 'cheese cheese', 'English cucumber', 'tomato tomato']\n"
]
}
],
"source": [
"list1 = ['Green', 'cheese', 'English', 'tomato']\n",
"list2 = ['eggs', 'cheese', 'cucumber', 'tomato']\n",
"zipped = zip(list1,list2)\n",
"list(zipped)"
"\n",
"new_list = [(lambda x, y : x + \" \" + y)(x, y) for x, y in zip(list1, list2)]\n",
"\n",
"print (new_list)"
]
},
{
Expand All @@ -209,17 +295,28 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 92,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[False, False, True, False]\n"
]
}
],
"source": [
"list1 = [1,2,4,4]\n",
"list2 = [2,3,3,5]\n",
"## Zip the lists together \n",
"\n",
"## Print the zipped list \n",
"together = [x > y for x, y in zip(list1, list2)]\n",
"\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n"
"## Print the zipped list \n",
"print (together)\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n",
"#???"
]
},
{
Expand All @@ -242,14 +339,25 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 57,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('Political Science', 'Essay'), ('Computer Science', 'Homework'), ('Engineering', 'Lab'), ('Mathematics', 'Module')]\n"
]
}
],
"source": [
"list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n",
"list2 = ['Lab', 'Homework', 'Essay', 'Module']\n",
"\n",
"# Your code here:\n"
"zipped = zip(list1, list2)\n",
"\n",
"sort = sorted(zipped, key=lambda x: x[1][0])\n",
"print(sort)"
]
},
{
Expand All @@ -263,21 +371,23 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 60,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'Toyota': 1995, 'Honda': 1997, 'Audi': 2001, 'BMW': 2005}\n"
]
}
],
"source": [
"d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n",
"\n",
"# Your code here:\n"
"new_sort = dict(sorted(d.items(), key=lambda x: x[1])) # o lambda x = 1 é para acessar o segundo valor da chave.\n",
"print(new_sort)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -296,7 +406,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down