From a1575d9ad19a646d6c31628f18d331237a544709 Mon Sep 17 00:00:00 2001 From: chasebeyer Date: Mon, 3 Feb 2025 18:17:08 +0000 Subject: [PATCH] lists - chase --- lists.ipynb | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 191 insertions(+), 1 deletion(-) diff --git a/lists.ipynb b/lists.ipynb index b766735..acf4ca6 100644 --- a/lists.ipynb +++ b/lists.ipynb @@ -6,7 +6,8 @@ "source": [ "# *List*omania\n", "\n", - "Lists are a key data structure for working with all kinds of data: text, numbers, and even more complex objects.\nThis is a string, not a list!\n", + "Lists are a key data structure for working with all kinds of data: text, numbers, and even more complex objects.\n", + "This is a string, not a list!\n", "\n", "## What is a list\n", "\n", @@ -18,6 +19,20 @@ "Let's make a list:" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": 1, @@ -1019,6 +1034,181 @@ "\n", "Complete Exercise 3-8 in Matthes (2023, p. 45)." ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "my_list = ['australia', 'spain', 'london', 'madagascar', 'prague' ]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['australia', 'spain', 'london', 'madagascar', 'prague']" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['australia', 'london', 'madagascar', 'prague', 'spain']" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(my_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['australia', 'spain', 'london', 'madagascar', 'prague']" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "my_list.reverse()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['prague', 'madagascar', 'london', 'spain', 'australia']" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "my_list.reverse()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['australia', 'spain', 'london', 'madagascar', 'prague']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "my_list.sort()" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['australia', 'london', 'madagascar', 'prague', 'spain']" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'reverse' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[25], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m my_list\u001b[38;5;241m.\u001b[39msort(\u001b[43mreverse\u001b[49m)\n", + "\u001b[0;31mNameError\u001b[0m: name 'reverse' is not defined" + ] + } + ], + "source": [] } ], "metadata": {