From 7279a35b9bb84060fbdc58476143161138f29a4f Mon Sep 17 00:00:00 2001 From: polserramalera Date: Mon, 26 Oct 2020 20:31:50 +0100 Subject: [PATCH] lab lambda functions commmited --- your-code/main.ipynb | 68 ++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..6aeed53 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -31,7 +31,7 @@ " Output: the transformed list\n", " \"\"\"\n", " \n", - " # your code here\n", + " return [lmbda(i) for i in lst]\n", " " ] }, @@ -46,11 +46,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "celsius_to_kelvin = lambda c: c + 273.15" ] }, { @@ -62,13 +62,24 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# your code here" + "modify_list(temps,celsius_to_kelvin)" ] }, { @@ -82,11 +93,11 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "mod=lambda x,y: 1 if x % y == 0 else 0" ] }, { @@ -100,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -110,8 +121,7 @@ " 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" + " return lambda x: 1 if x % b == 0 else 0" ] }, { @@ -123,11 +133,11 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "divisible5 = divisor(5)" ] }, { @@ -139,18 +149,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -269,7 +301,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.3" } }, "nbformat": 4,