From 38182c4493b00b5cacbc0f88233b171b8894ed5e Mon Sep 17 00:00:00 2001 From: Anna Meyer <annapmeyer95@gmail.com> Date: Mon, 10 Jul 2023 09:34:01 -0500 Subject: [PATCH] list code template change --- .../08_Lists/lec_08_lists_template.ipynb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sum23/lecture_materials/08_Lists/lec_08_lists_template.ipynb b/sum23/lecture_materials/08_Lists/lec_08_lists_template.ipynb index d4263de..1cff2f5 100644 --- a/sum23/lecture_materials/08_Lists/lec_08_lists_template.ipynb +++ b/sum23/lecture_materials/08_Lists/lec_08_lists_template.ipynb @@ -137,6 +137,14 @@ "print(grocery_list[len(grocery_list)])" ] }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Write loops that process lists" + ] + }, { "cell_type": "code", "execution_count": null, @@ -194,6 +202,27 @@ "How does Python differentiate between two different usages of `[]`?" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def longest_word(word_list):\n", + " '''Given a list of strings, return the string with the longest length.\n", + " If more than one, return the first one.'''\n", + "\n", + " max_length = 0\n", + " longest_word = None\n", + "\n", + " return longest_word\n", + "\n", + "print(grocery_list)\n", + "print(longest_word(grocery_list))\n", + "print(longest_word([\"aaaa\", \"xyz\", \"hello\"]))\n", + "print(longest_word([]))" + ] + }, { "attachments": {}, "cell_type": "markdown", -- GitLab