From f339263b05cad46f0268fd2192a50b3d1eecb9d4 Mon Sep 17 00:00:00 2001 From: kaylielau Date: Wed, 11 Mar 2026 17:29:36 -0400 Subject: [PATCH] Upload 03_11_2026 live code --- 04_this_cohort/live-code/03_09_2026.ipynb | 115 +- 04_this_cohort/live-code/03_11_2026.ipynb | 2359 +++++++++++++++++++++ 2 files changed, 2472 insertions(+), 2 deletions(-) create mode 100644 04_this_cohort/live-code/03_11_2026.ipynb diff --git a/04_this_cohort/live-code/03_09_2026.ipynb b/04_this_cohort/live-code/03_09_2026.ipynb index c443c4cac..274622872 100644 --- a/04_this_cohort/live-code/03_09_2026.ipynb +++ b/04_this_cohort/live-code/03_09_2026.ipynb @@ -2182,16 +2182,127 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 157, "id": "5d4da1e1", "metadata": {}, "outputs": [], "source": [ - "year = 2026\n", + "year = 1990\n", "\n", "if year >= 2000:\n", " print(\"We are in the 21st century.\")" ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "9085b674", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Good job!\n" + ] + } + ], + "source": [ + "breakfast_eaten = 'yes'\n", + "\n", + "if breakfast_eaten == 'yes':\n", + " print('Good job!')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9617932e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century.\n" + ] + } + ], + "source": [ + "# else statement tells Python what code to run if the condition evaluates \n", + "# to false\n", + "\n", + "year = 2001\n", + "\n", + "if year >= 2000:\n", + " print('We are in the 21st century.')\n", + "else:\n", + " print('We are not in the 21st century.')" + ] + }, + { + "cell_type": "code", + "execution_count": 165, + "id": "ab8defa0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 20th century.\n" + ] + } + ], + "source": [ + "year = 1992\n", + "\n", + "if year >= 2000:\n", + " print('We are in the 21st century.')\n", + "elif year >= 1900:\n", + " print('We are in the 20th century.')\n", + "elif year >= 1800:\n", + " print('We are in the 19th century.')\n", + "else:\n", + " print('We are way back in time!')" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "id": "35dfeb61", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century.\n", + "We are in the 20th century.\n", + "We are in the 19th century.\n" + ] + } + ], + "source": [ + "year = 2026\n", + "\n", + "if year >= 2000:\n", + " print('We are in the 21st century.')\n", + "if year >= 1900:\n", + " print('We are in the 20th century.')\n", + "if year >= 1800:\n", + " print('We are in the 19th century.')\n", + "else:\n", + " print('We are way back in time!')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "afdd51c2", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/04_this_cohort/live-code/03_11_2026.ipynb b/04_this_cohort/live-code/03_11_2026.ipynb new file mode 100644 index 000000000..c75bc8026 --- /dev/null +++ b/04_this_cohort/live-code/03_11_2026.ipynb @@ -0,0 +1,2359 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "13a04d9b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Weekend\n" + ] + } + ], + "source": [ + "day_of_week = 'Saturday'\n", + "\n", + "if (day_of_week == 'Saturday') or (day_of_week == 'Sunday'): # True or False\n", + " print('Weekend')\n", + "else:\n", + " print('Weekday')" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "bb9e2835", + "metadata": {}, + "outputs": [], + "source": [ + "def eye_exam_covered(age, qualifying_condition, time_since_last_exam):\n", + " '''assume (1) age is passed as an int is for the age of a person\n", + " \n", + " (2) qualifying_condition is passed as a bool (True/False) \n", + " indicating whether a eligible medical condition is met, \n", + " \n", + " and (3) time_since_last_exam is passed as an int for the \n", + " number of months since the last eye exam'''\n", + "\n", + " if 0 <= age <= 19:# False\n", + " if time_since_last_exam >= 12:\n", + " return \"You are eligible for 1 major eye exam and any minor assessments\"\n", + " else:\n", + " return \"It hasn't been 12 months since your last major eye exam.\"\n", + " elif 20 <= age <= 64: # True\n", + " if qualifying_condition: # if True:\n", + " if time_since_last_exam >=12: # True\n", + " return \"You are eligible for 1 major eye exam and 2 additional follow-up minor assessments\"\n", + " else:\n", + " return \"It hasn't been 12 months since your last major eye exam\"\n", + " else:\n", + " return \"You do not have a qualifying eligible medical condition.\"\n", + " elif age >= 65:\n", + " if time_since_last_exam >= 18:\n", + " return \"You are eligible for 1 major eye exam and 2 additional follow-up minor assessments\"\n", + " else:\n", + " return \"It hasn't been 18 months since your last major eye exam.\"\n", + " else:\n", + " return \"Invalid age input.\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "11ef9180", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'You are eligible for 1 major eye exam and 2 additional follow-up minor assessments'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(27, True, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "bd427881", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"It hasn't been 12 months since your last major eye exam.\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(19, False, 11)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0731d747", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'<' not supported between instances of 'str' and 'int'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[33;43m'\u001b[39;49m\u001b[33;43m19\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m<\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m19\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: '<' not supported between instances of 'str' and 'int'" + ] + } + ], + "source": [ + "'19' < 19" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "68cc9d92", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Invalid age input.'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(-10, True, 12)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "3431161c", + "metadata": {}, + "outputs": [], + "source": [ + "def subtract(a, b):\n", + " output = a - b\n", + " print(output)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "8f601e4f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], + "source": [ + "subtract2 = subtract(10, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "ee54f770", + "metadata": {}, + "outputs": [], + "source": [ + "subtract2" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "2ea39e1b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# lists\n", + "# []\n", + "\n", + "vowels =['a', 'e', 'i', 'o', 'u']\n", + "vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a9ccbbf1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "empty_list = []\n", + "empty_list" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "cdb686b5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "empty_list2 = list()\n", + "empty_list2" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "ab21241c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[90, 80, 82, 91, 80]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scores = [90, 80, 82, 91, 80]\n", + "scores" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "0844c990", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['K', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades = ['K', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n", + "grades" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "460db457", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['Sherlock', 'Watson'],\n", + " ['Scooby', 'Shaggy', 'Fred', 'Velma', 'Daphne'],\n", + " 'Nancy']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mystery_solvers = [\n", + " ['Sherlock', 'Watson'],\n", + " ['Scooby', 'Shaggy', 'Fred', 'Velma', 'Daphne'],\n", + " 'Nancy'\n", + "]\n", + "mystery_solvers" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "037d07b7", + "metadata": {}, + "outputs": [], + "source": [ + "# ordered: each item in a list can be referenced by its index (or position) in the list" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "26b24e6c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['K', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "449981bd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'K'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "bfdecb4d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades[4]" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "d3d006f6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[3, 4, 5]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades[3:6]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "63a152dc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades[-4]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "aca47845", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['Sherlock', 'Watson'],\n", + " ['Scooby', 'Shaggy', 'Fred', 'Velma', 'Daphne'],\n", + " 'Nancy']" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mystery_solvers" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "6cb06ee8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Sherlock'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mystery_solvers[0][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "a5c2f50d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['K', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "ef5bdd38", + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mIndexError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[26]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mgrades\u001b[49m\u001b[43m[\u001b[49m\u001b[32;43m13\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[31mIndexError\u001b[39m: list index out of range" + ] + } + ], + "source": [ + "grades[13]" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "dc9e040a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 37, 49]" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# lists are mutable\n", + "# modified in place\n", + "\n", + "# strings, ints, flaots -> immutable \n", + "# cannot be changed\n", + "# when we update a immutable data type we are replace the value entirely\n", + "\n", + "perfect_squares = [1, 4, 9, 16, 25, 37, 49]\n", + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "1218a9a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares[5] = 36\n", + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "5069a35f", + "metadata": {}, + "outputs": [], + "source": [ + "julia = ['bread', 'cheese', 'bread']" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "f7b108ae", + "metadata": {}, + "outputs": [], + "source": [ + "kaylie = julia" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "6578d16f", + "metadata": {}, + "outputs": [], + "source": [ + "julia[1] = 'tomato'" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "a5b17017", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'tomato', 'bread']" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "f7a04939", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'tomato', 'bread']" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "77263cfa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia = 'cheese sandwich'\n", + "julia" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "eeb5131a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie = julia\n", + "kaylie" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "b9150f02", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'tomato sandwich'" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia = 'tomato sandwich'\n", + "julia" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "fb8b4a8c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kaylie" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "52620b9d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = 1\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "43dcff44", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = a\n", + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "54222048", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = 2\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "1af56e56", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "74cffdf2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2]" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = [1, 2]\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "0eb20317", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2]" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = a\n", + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "8ed78e5f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[6, 2]" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a[0] = 6\n", + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "5b5011f9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[6, 2]" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "3a4db8d8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "combo = ['burger', 'fries', 'drink']\n", + "kid_meal = list(combo) # independent copy of a list\n", + "combo" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "47906030", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kid_meal" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "00a0ffd8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['chicken sandwich', 'fries', 'drink']" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "combo[0] = 'chicken sandwich'\n", + "combo" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "07b1b0de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kid_meal" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "694409c0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49]" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "ed781281", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "fa8e25a0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "49" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "2dd1c2f9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "140" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "31718983", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'b', 'c', 1, 2, 3]" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "letters =['a', 'b', 'c']\n", + "numbers = [1, 2, 3]\n", + "characters = letters + numbers\n", + "characters" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "b64c67a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'b', 'c', 'a', 'b', 'c']" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "letters * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "2e4227af", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 1, 2, 3]" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numbers * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "1170d786", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'b', 'c']" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "letters" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "ab8b6ff8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3]" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "8103fefc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red', 'orange', 'yellow', 'green', 'light blue', 'blue', 'violet']" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow = ['red', 'orange', 'yellow', 'green', 'light blue', 'blue', 'violet']\n", + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "272ad4b7", + "metadata": {}, + "outputs": [], + "source": [ + "# .append() is used to add a single element to the end of a list\n", + "# take one argument which is the element to be added to the list" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "19966826", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.append('purple')" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "82c791e2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red', 'orange', 'yellow', 'green', 'light blue', 'blue', 'violet', 'purple']" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "8a6be4af", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.append(['purple'])" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "8856192c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " ['purple']]" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "841838bb", + "metadata": {}, + "outputs": [], + "source": [ + "# .extend() is used to add elements from an iterable to the end of a list\n", + "# take one argument which is an iterable\n", + "# unpack the elements of the iterable and add them one by one to the end of the original list" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "d8da2671", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " ['purple']]" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "83d947fe", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.extend('purple')" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "08ee4f24", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " ['purple'],\n", + " 'p',\n", + " 'u',\n", + " 'r',\n", + " 'p',\n", + " 'l',\n", + " 'e']" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "f6c544db", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.extend(['purple', 'green'])" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "8dae45ba", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " ['purple'],\n", + " 'p',\n", + " 'u',\n", + " 'r',\n", + " 'p',\n", + " 'l',\n", + " 'e',\n", + " 'purple',\n", + " 'green']" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "id": "1f1dc267", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " ['purple'],\n", + " 'p',\n", + " 'u',\n", + " 'r',\n", + " 'p',\n", + " 'l',\n", + " 'e',\n", + " 'purple',\n", + " 'green']" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "id": "258b9bfe", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.insert(6, 'indigo')" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "d966872f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'indigo',\n", + " 'violet',\n", + " 'purple',\n", + " ['purple'],\n", + " 'p',\n", + " 'u',\n", + " 'r',\n", + " 'p',\n", + " 'l',\n", + " 'e',\n", + " 'purple',\n", + " 'green']" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "298ad672", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'light blue',\n", + " 'blue',\n", + " 'indigo',\n", + " 'violet',\n", + " 'purple',\n", + " ['purple'],\n", + " 'u',\n", + " 'r',\n", + " 'p',\n", + " 'l',\n", + " 'e',\n", + " 'purple',\n", + " 'green']" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.remove('p')\n", + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "6b9e8e19", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.clear()" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "2f96dcf9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "96bb582f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['pineapple', 'apple', 'kiwi', 'banana']" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruits = ['pineapple', 'apple', 'kiwi', 'banana']\n", + "fruits" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "cf85c727", + "metadata": {}, + "outputs": [], + "source": [ + "# .sort() method\n", + "\n", + "fruits.sort()" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "02c46e9c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['apple', 'banana', 'kiwi', 'pineapple']" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruits" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5adf001", + "metadata": {}, + "outputs": [], + "source": [ + "# sorted() function" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "id": "b2323d29", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['potato', 'celery', 'cabbage', 'bell pepper', 'onion']" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "veggies = ['potato', 'celery', 'cabbage', 'bell pepper', 'onion']\n", + "veggies" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "45808f0a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bell pepper', 'cabbage', 'celery', 'onion', 'potato']" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(veggies)" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "bb05f366", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['potato', 'celery', 'cabbage', 'bell pepper', 'onion']" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "veggies" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "id": "517e7e98", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('changeable', 'fluctuating', 'inconstant', 'variable')" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# tuple\n", + "# immutable (cannot be changed once it is created)\n", + "# ordered\n", + "\n", + "mutable_synonyms = ('changeable', 'fluctuating', 'inconstant', 'variable')\n", + "mutable_synonyms" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "7072ecb5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "()" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "empty_tuple = ()\n", + "empty_tuple" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "id": "a766eaa6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "()" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "also_empty = tuple()\n", + "also_empty" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "id": "f29b9e61", + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'tuple' object has no attribute 'append'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[90]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mempty_tuple\u001b[49m\u001b[43m.\u001b[49m\u001b[43mappend\u001b[49m(\u001b[33m'\u001b[39m\u001b[33mhi\u001b[39m\u001b[33m'\u001b[39m)\n", + "\u001b[31mAttributeError\u001b[39m: 'tuple' object has no attribute 'append'" + ] + } + ], + "source": [ + "empty_tuple.append('hi')" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "ef88901b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('changeable', 'fluctuating', 'inconstant', 'variable')" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mutable_synonyms" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "bb8ee85d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(mutable_synonyms)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "9c68e8be", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['changeable', 'fluctuating', 'inconstant', 'variable']" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(mutable_synonyms)" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "926fd983", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('changeable',\n", + " 'fluctuating',\n", + " 'inconstant',\n", + " 'variable',\n", + " 'modifiable',\n", + " 'shifting')" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mutable_synonyms + ('modifiable', 'shifting')" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "71e1f641", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('changeable', 'fluctuating', 'inconstant', 'variable')" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mutable_synonyms" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b9e5c327", + "metadata": {}, + "outputs": [], + "source": [ + "# \"ordered\" vs \"unordered\"\n", + "# whether the sequence or arrangment of elements within the collection is maintained" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d91db22", + "metadata": {}, + "outputs": [], + "source": [ + "# set\n", + "# mutable\n", + "# unordered -> elements do not maintain any specific order\n", + "# distinct -> all elements are unique\n" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "id": "2c2762b0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'xylophone'}" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things = {'coat', 'lock', 'box', 'book', 'apple', 'hair', 'xylophone', 'lock', 'book'}\n", + "things" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "32c37771", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['M5R', 'M5V', 'M1M', 'M1M', 'M1T']" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "visitor_post_code = ['M5R', 'M5V', 'M1M', 'M1M', 'M1T']\n", + "visitor_post_code" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "161f25ce", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'M1M', 'M1T', 'M5R', 'M5V'}" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set(visitor_post_code)" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "fead03e5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "set()" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "empty_set = set()\n", + "empty_set" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "2c764b41", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'xylophone'}" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "c3442aba", + "metadata": {}, + "outputs": [], + "source": [ + "things.add('lock')" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "282ecb4e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'xylophone'}" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "3b2e1209", + "metadata": {}, + "outputs": [], + "source": [ + "things.add('mirror')" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "cfeded60", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'apple', 'book', 'box', 'coat', 'hair', 'lock', 'mirror', 'xylophone'}" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "1e5a2f23", + "metadata": {}, + "outputs": [], + "source": [ + "things.remove('apple')" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "9f6f501f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'box', 'coat', 'hair', 'lock', 'mirror', 'xylophone'}" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "things" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "1a8c6629", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'set' object is not subscriptable", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[109]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mthings\u001b[49m\u001b[43m[\u001b[49m\u001b[32;43m1\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[31mTypeError\u001b[39m: 'set' object is not subscriptable" + ] + } + ], + "source": [ + "things[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "id": "94486e4e", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow = {'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'}\n", + "olympic_flag = {'red', 'green', 'yellow', 'blue', 'black'}" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "id": "142efd8b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'indigo', 'orange', 'violet'}" + ] + }, + "execution_count": 112, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# difference: find the values in the first set that are not in the second set\n", + "\n", + "rainbow.difference(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "id": "fd1c44aa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'black'}" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "olympic_flag.difference(rainbow)" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "b746c2de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'black', 'indigo', 'orange', 'violet'}" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# symmetric difference: find values that are in only one of the two sets\n", + "\n", + "rainbow.symmetric_difference(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "f73f3e9e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'blue', 'green', 'indigo', 'orange', 'red', 'violet', 'yellow'}" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "84a1043d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'black', 'blue', 'green', 'red', 'yellow'}" + ] + }, + "execution_count": 116, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "olympic_flag" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a3a49763", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'blue', 'green', 'red', 'yellow'}" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# intersection find the values the two sets have in common\n", + "\n", + "rainbow.intersection(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "id": "8981aa9a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'black', 'blue', 'green', 'indigo', 'orange', 'red', 'violet', 'yellow'}" + ] + }, + "execution_count": 118, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# union combine two sets to get the unique values in both\n", + "\n", + "rainbow.union(olympic_flag)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5730bae7", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-env", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}