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 d4263de556457540e7bdd731529959517d31422e..1cff2f54f950ec3dbeca0a49ad062d67c0e25603 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",