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
195 changes: 159 additions & 36 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,43 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# your code here\n"
"# your code here\n",
"def modify_list(lis,lam):\n",
" emp=[lam(i) for i in lis]\n",
" ## You can also.\n",
" for i in range(len(emp2)):\n",
" emp2.append(lam(lis(i)))\n",
" return emp\n",
"\n",
"\n",
"my_list = [1,3,5,4,8,9,6,1,6,5]\n",
"egg =lambda x: x+2\n",
"emp2 = []\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 5, 7, 6, 10, 11, 8, 3, 8, 7]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"modify_list(my_list,egg)"
]
},
{
Expand All @@ -52,11 +84,12 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"# Your code here:\n",
"kel=lambda x: x+273.15\n"
]
},
{
Expand All @@ -68,13 +101,25 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"[kel(i) for i in temps]\n"
]
},
{
Expand All @@ -88,11 +133,12 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 106,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"# Your code here:\n",
"mod=lambda a: ((a/b)*0)+1 if a%b==0 else (a/b)*0"
]
},
{
Expand All @@ -106,16 +152,13 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 107,
"metadata": {},
"outputs": [],
"source": [
"def divisor(a):\n",
" \"\"\"\n",
" 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"
"def divisor(b):\n",
" mod=lambda a: ((a/b)*0)+1 if a%b==0 else (a/b)*0\n",
" return mod\n"
]
},
{
Expand All @@ -127,11 +170,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 108,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"divisible5= divisor(5)"
]
},
{
Expand All @@ -143,18 +186,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 109,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 110,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 110,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
]
Expand Down Expand Up @@ -209,17 +274,37 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 136,
"metadata": {},
"outputs": [],
"source": [
"list1 = [1,2,4,4]\n",
"list2 = [2,3,3,5]\n",
"## Zip the lists together \n",
"\n",
"zippy=zip(list1,list2)\n",
"## Print the zipped list \n",
"\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n"
"zippy =list(zippy)\n",
"zipup=lambda z: [(i[0]>i[1])for i in z]\n"
]
},
{
"cell_type": "code",
"execution_count": 137,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[False, False, True, False]"
]
},
"execution_count": 137,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"zipup(zippy)"
]
},
{
Expand All @@ -242,14 +327,31 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 148,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[('Political Science', 'Essay'),\n",
" ('Computer Science', 'Homework'),\n",
" ('Engineering', 'Lab'),\n",
" ('Mathematics', 'Module')]"
]
},
"execution_count": 148,
"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"
"# Your code here:\n",
"task= list(zip(list1,list2))\n",
"task.sort(key=lambda x: x[1])\n",
"task"
]
},
{
Expand All @@ -263,26 +365,42 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 157,
"metadata": {},
"outputs": [],
"source": [
"d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n",
"\n",
"# Your code here:\n"
"# Your code here:"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 170,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"{'Toyota': 1995, 'Honda': 1997, 'Audi': 2001, 'BMW': 2005}"
]
},
"execution_count": 170,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"myzip=list(zip(list(d.keys()),list(d.values())))\n",
"myzip.sort(key=lambda x: x[1])\n",
"d=dict(myzip)\n",
"d"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3.9.13 ('Ironhack')",
"language": "python",
"name": "python3"
},
Expand All @@ -296,7 +414,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "985844dc686bf8bc52028a38ef08654e50758646994bdb41b244f06f0e25b2ae"
}
}
},
"nbformat": 4,
Expand Down