diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..f6e7a47 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -32,7 +32,7 @@ " \"\"\"\n", " \n", " # your code here\n", - " " + " return lambda lst,lmbda: lst*lambda\n" ] }, { @@ -46,11 +46,25 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "276.15" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "F = lambda x: x+273.15\n", + "\n", + "F(3)" ] }, { @@ -62,13 +76,28 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# your code here" + "# your code here\n", + "\n", + "temps_K = list(map(lambda x: x + 273.15, temps))\n", + "\n", + "temps_K\n" ] }, { @@ -84,9 +113,23 @@ "cell_type": "code", "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "mod = lambda x,y: 1 if (x % y == 0 and x > y) else 0\n", + "mod(16,3)" ] }, { @@ -100,18 +143,36 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "\n", "def divisor(b):\n", - " \"\"\"\n", - " Input: a number\n", - " Output: a function that returns 1 if the number is \n", - " divisible by another number (to be passed later) and zero otherwise.\n", - " \"\"\"\n", + " #\"\"\"\n", + " #Input: a number\n", + " #Output: a function that returns 1 if the number is \n", + " #divisible by another number (to be passed later) and zero otherwise.\n", + " #\"\"\"\n", " \n", - " # your code here" + " # your code here\n", + " \n", + " return lambda x: 1 if (x % b == 0 and x > b) else 0\n", + "\n", + "mod = divisor(3)\n", + "\n", + "mod(15)\n" ] }, { @@ -123,11 +184,37 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "def divisible5(b):\n", + " #\"\"\"\n", + " #Input: a number\n", + " #Output: a function that returns 1 if the number is \n", + " #divisible by another number (to be passed later) and zero otherwise.\n", + " #\"\"\"\n", + " \n", + " # your code here\n", + " \n", + " return lambda x: 1 if (x % b == 0 and x > b) else 0\n", + "\n", + "mod = divisible5(5)\n", + "\n", + "mod(15)" ] }, { @@ -139,20 +226,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "divisible5(10)" + "def divisible5(b):\n", + " #\"\"\"\n", + " #Input: a number\n", + " #Output: a function that returns 1 if the number is \n", + " #divisible by another number (to be passed later) and zero otherwise.\n", + " #\"\"\"\n", + " \n", + " # your code here\n", + " \n", + " return lambda x: 1 if (x % b == 0 and x > b) else 0\n", + "\n", + "mod = divisible5(10)\n", + "\n", + "mod(100)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "divisible5(8)" + "def divisible5(b):\n", + " #\"\"\"\n", + " #Input: a number\n", + " #Output: a function that returns 1 if the number is \n", + " #divisible by another number (to be passed later) and zero otherwise.\n", + " #\"\"\"\n", + " \n", + " # your code here\n", + " \n", + " return lambda x: 1 if (x % b == 0 and x > b) else 0\n", + "\n", + "mod = divisible5(8)\n", + "\n", + "mod(16)" ] }, { @@ -168,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 67, "metadata": {}, "outputs": [ { @@ -177,7 +312,7 @@ "[(1,), (2,), (3,), (4,), (5,)]" ] }, - "execution_count": 10, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -199,14 +334,32 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 65, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Green', 'eggs'),\n", + " ('cheese', 'cheese'),\n", + " ('English', 'cucumber'),\n", + " ('tomato', 'tomato')]" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Green', 'cheese', 'English', 'tomato']\n", "list2 = ['eggs', 'cheese', 'cucumber', 'tomato']\n", "\n", - "# your code here" + "# your code here\n", + "\n", + "list3 = zip(list1,list2)\n", + "\n", + "list(list3)\n" ] }, { @@ -222,14 +375,64 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 98, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", - "# your code here" + "# your code here\n", + "\n", + "list1.sort()\n", + "\n", + "list1\n", + "\n", + "\n", + "list3 = list(map(lambda x: zip(x,y),list2))\n", + "\n", + "\n", + "pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]\n", + "\n", + "pairs.sort(key=lambda pair: pair[0])\n", + "pairs" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 4), (2, 5), (3, 6)]" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = [1, 2, 3]\n", + "y = [4, 5, 6]\n", + "zipped = zip(x, y)\n", + "list(zipped)\n", + "#[(1, 4), (2, 5), (3, 6)]\n", + "#x2, y2 = zip(*zip(x, y))\n", + "#x == list(x2) and y == list(y2)" ] }, { @@ -269,7 +472,43 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.5" + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "position": { + "height": "333.722px", + "left": "1375.45px", + "right": "20px", + "top": "120px", + "width": "350px" + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false } }, "nbformat": 4,