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
271 changes: 232 additions & 39 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,59 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# your code here\n"
"modify_list = [1,2,3,4,5,6,7,8,9,10]"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = (list(map(lambda x : x*2, modify_list)))\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"list_3 = []"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, <function <lambda> at 0x7ff5a80a1820>, <function <lambda> at 0x7ff5a80a1280>]\n"
]
}
],
"source": [
"list_3.append(lambda x:x+1) \n",
"print(list_3)"
]
},
{
Expand All @@ -52,11 +100,32 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 132,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter temperature in celsius: 3\n",
"[276.15]\n"
]
}
],
"source": [
"celsius = input('Enter temperature in celsius: ')\n",
"\n",
"kelvin = list(map(lambda x : int(x)+273.15,(celsius)))\n",
"print(kelvin)"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"273.15 + celsius"
]
},
{
Expand All @@ -68,13 +137,24 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 98,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]"
]
},
"execution_count": 98,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"celsius = [12, 23, 38, -55, 24]\n",
"\n",
"# Your code here:\n"
"list(map(lambda x : x+273.15, (celsius)))\n"
]
},
{
Expand All @@ -88,11 +168,26 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 231,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"3\n",
"0\n"
]
}
],
"source": [
"# Your code here:\n"
"inp = int(input())\n",
"\n",
"if list(filter(lambda x: (x % int(input()) == 0), [inp])) == 0:\n",
" print(\"1\")\n",
"else:\n",
" print('0')"
]
},
{
Expand All @@ -106,16 +201,21 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 236,
"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"
" #\"\"\"\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",
" inp = int(input())\n",
"\n",
" if list(filter(lambda x: (x % int(input()) == 0), [inp])) == 0:\n",
" print(\"1\")\n",
" else:\n",
" print('0')"
]
},
{
Expand All @@ -127,11 +227,24 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 252,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100\n",
"Numbers divisible by 5 are [100]\n"
]
}
],
"source": [
"# Your code here:\n"
"inp = [int(input())]\n",
"\n",
"divisible5 = list(filter(lambda x: (x % 5 == 0), (inp)))\n",
"\n",
"print(\"Numbers divisible by 5 are\",divisible5)"
]
},
{
Expand All @@ -143,20 +256,46 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 257,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20\n",
"Numbers divisible by 10 are [20]\n"
]
}
],
"source": [
"divisible5(10)"
"inp = [int(input())]\n",
"\n",
"divisible10 = list(filter(lambda x: (x % 10 == 0), (inp)))\n",
"\n",
"print(\"Numbers divisible by 10 are\",divisible10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 256,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"16\n",
"Numbers divisible by 8 are [16]\n"
]
}
],
"source": [
"divisible5(8)"
"inp = [int(input())]\n",
"\n",
"divisible8 = list(filter(lambda x: (x % 8 == 0), (inp)))\n",
"\n",
"print(\"Numbers divisible by 8 are\",divisible8)"
]
},
{
Expand All @@ -174,7 +313,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 291,
"metadata": {},
"outputs": [
{
Expand All @@ -186,7 +325,7 @@
" ('tomato', 'tomato')]"
]
},
"execution_count": 1,
"execution_count": 291,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -209,17 +348,56 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 301,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[(1, 2), (2, 3), (4, 3), (4, 5)]"
]
},
"execution_count": 301,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list1 = [1,2,4,4]\n",
"list2 = [2,3,3,5]\n",
"## Zip the lists together \n",
"list3 = [1,2,4,4]\n",
"list4 = [2,3,3,5]\n",
"\n",
"## Print the zipped list \n",
"\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n"
"zipped1 = zip(list3,list4)\n",
"list(zipped1)"
]
},
{
"cell_type": "code",
"execution_count": 302,
"metadata": {},
"outputs": [],
"source": [
"list_5 = list(map(lambda x: map(lambda y: y == x, list_3), list_4))\n",
"list_5"
]
},
{
"cell_type": "code",
"execution_count": 312,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[]\n"
]
}
],
"source": [
"equal = lambda x:x in list_3\n",
"equal = list(map(is_it_equal_function, list_4))\n",
"print(equal)"
]
},
{
Expand All @@ -242,14 +420,29 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 317,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[('Political Science', 'Essay'),\n",
" ('Computer Science', 'Homework'),\n",
" ('Engineering', 'Lab'),\n",
" ('Mathematics', 'Module')]"
]
},
"execution_count": 317,
"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"
"\n",
"sorted(zip(list1, list2), key=lambda x: x[1])"
]
},
{
Expand Down Expand Up @@ -296,7 +489,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.8"
}
},
"nbformat": 4,
Expand Down