From 79ec3193e1d53fce6138a2e66de7a279d249eb16 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 21 Jun 2018 09:39:43 -0400 Subject: [PATCH 1/5] added license and contributing --- CONTRIBUTING.md | 37 +++++++++++++++++++++++++++++++++++++ LICENSE.md | 23 +++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000000..dd12a2a4693 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +# Contributing to Learn.co Curriculum + +We're really exited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible. + +## Raising an Issue to Encourage a Contribution + +If you notice a problem with the curriculum that you believe needs improvement +but you're unable to make the change yourself, you should raise a Github issue +containing a clear description of the problem. Include relevant snippets of +the content and/or screenshots if applicable. Curriculum owners regularly review +issue lists and your issue will be prioritized and addressed as appropriate. + +## Submitting a Pull Request to Suggest an Improvement + +If you see an opportunity for improvement and can make the change yourself go +ahead and use a typical git workflow to make it happen: + +* Fork this curriculum repository +* Make the change on your fork, with descriptive commits in the standard format +* Open a Pull Request against this repo + +A curriculum owner will review your change and approve or comment on it in due +course. + +# Why Contribute? + +Curriculum on Learn is publicly and freely available under Learn's +[Educational Content License](https://learn.co/content-license). By +embracing an open-source contribution model, our goal is for the curriculum +on Learn to become, in time, the best educational content the world has +ever seen. + +We need help from the community of Learners to maintain and improve the +educational content. Everything from fixing typos, to correcting +out-dated information, to improving exposition, to adding better examples, +to fixing tests—all contributions to making the curriculum more effective are +welcome. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000000..a297d511e15 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +# Learn.co Educational Content License + +Copyright (c) 2018 Flatiron School, Inc + +The Flatiron School, Inc. owns this Educational Content. However, the Flatiron +School supports the development and availability of educational materials in +the public domain. Therefore, the Flatiron School grants Users of the Flatiron +Educational Content set forth in this repository certain rights to reuse, build +upon and share such Educational Content subject to the terms of the Educational +Content License set forth [here](http://learn.co/content-license) +(http://learn.co/content-license). You must read carefully the terms and +conditions contained in the Educational Content License as such terms govern +access to and use of the Educational Content. + +Flatiron School is willing to allow you access to and use of the Educational +Content only on the condition that you accept all of the terms and conditions +contained in the Educational Content License set forth +[here](http://learn.co/content-license) (http://learn.co/content-license). By +accessing and/or using the Educational Content, you are agreeing to all of the +terms and conditions contained in the Educational Content License. If you do +not agree to any or all of the terms of the Educational Content License, you +are prohibited from accessing, reviewing or using in any way the Educational +Content. From d8fca993a775925f1a7dac897cbfeec532408a57 Mon Sep 17 00:00:00 2001 From: Lore Dirick Date: Thu, 14 Feb 2019 15:36:58 -0500 Subject: [PATCH 2/5] fix solution for unique countries list --- README.md | 23 +---------- index.ipynb | 115 +++++++++++++++------------------------------------- 2 files changed, 34 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index b6e0c123712..ccfaed3fbe7 100644 --- a/README.md +++ b/README.md @@ -140,25 +140,6 @@ countries # ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta'] ``` - - - - ['Croatia', - 'USA', - 'Argentina', - 'Mexico', - 'USA', - 'Morocco', - 'USA', - 'Finland', - 'Argentina', - 'Italy', - 'Canada', - 'South Korea', - 'Malta'] - - - ### Exploring Lists with Methods Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list. @@ -172,8 +153,8 @@ unique_countries = None ```python -unique_countries # ['Canada', 'Italy', 'USA', 'Mexico', 'Finland', -#'Malta', 'Morocco', 'Croatia', 'Argentina', 'South Korea'] +unique_countries # ['USA', 'Finland', 'Argentina', 'South Korea', 'Morocco', +#'Croatia','Mexico','Malta','Italy','Canada'] ``` Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`. diff --git a/index.ipynb b/index.ipynb index bea966e94d1..f20dfd8fae5 100644 --- a/index.ipynb +++ b/index.ipynb @@ -55,10 +55,8 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']" @@ -80,10 +78,8 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "countries = ['Croatia',\n", @@ -131,10 +127,8 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "italy = None # 'Italy'\n", @@ -150,10 +144,8 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "italy # 'Italy'" @@ -168,10 +160,8 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "mexico = None\n", @@ -187,10 +177,8 @@ }, { "cell_type": "code", - "execution_count": 21, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "kindof_neighbors = None\n", @@ -213,10 +201,8 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "None # add code here" @@ -231,10 +217,8 @@ }, { "cell_type": "code", - "execution_count": 25, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "None # add code here" @@ -250,9 +234,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "countries \n", @@ -270,9 +252,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "None # add code here" @@ -281,9 +261,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "countries \n", @@ -300,32 +278,9 @@ }, { "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['Croatia',\n", - " 'USA',\n", - " 'Argentina',\n", - " 'Mexico',\n", - " 'USA',\n", - " 'Morocco',\n", - " 'USA',\n", - " 'Finland',\n", - " 'Argentina',\n", - " 'Italy',\n", - " 'Canada',\n", - " 'South Korea',\n", - " 'Malta']" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "countries = ['Croatia',\n", " 'USA',\n", @@ -370,9 +325,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "unique_countries = None" @@ -381,13 +334,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "unique_countries # ['Canada', 'Italy', 'USA', 'Mexico', 'Finland', \n", - "#'Malta', 'Morocco', 'Croatia', 'Argentina', 'South Korea']" + "unique_countries # ['USA', 'Finland', 'Argentina', 'South Korea', 'Morocco',\n", + "#'Croatia','Mexico','Malta','Italy','Canada']" ] }, { @@ -400,9 +351,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "num_of_repeats = None\n", @@ -428,21 +377,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.14" + "pygments_lexer": "ipython3", + "version": "3.6.4" } }, "nbformat": 4, From 388ac99ac2b0f0d6da29729ee72cb041add736e8 Mon Sep 17 00:00:00 2001 From: Matt Stetz Date: Fri, 30 Aug 2019 13:43:51 -0400 Subject: [PATCH 3/5] create solution branch --- README.md | 6 +- index.ipynb | 400 +--------------------------------------------------- 2 files changed, 4 insertions(+), 402 deletions(-) diff --git a/README.md b/README.md index ccfaed3fbe7..74d3cc5c133 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ You may have noticed that "New Mexico" is included in our list of countries. Th ```python -None # add code here +countries = None # add code here ``` @@ -153,8 +153,8 @@ unique_countries = None ```python -unique_countries # ['USA', 'Finland', 'Argentina', 'South Korea', 'Morocco', -#'Croatia','Mexico','Malta','Italy','Canada'] +unique_countries # ['Croatia', 'Argentina', 'Canada', 'Mexico', 'Italy', +#'South Korea', 'USA', 'Morocco', 'Malta', 'Finland'] Note: order of countries may be different ``` Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`. diff --git a/index.ipynb b/index.ipynb index f20dfd8fae5..9b2df0807cc 100644 --- a/index.ipynb +++ b/index.ipynb @@ -1,399 +1 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "# Lists Lab " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Introduction" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's put this knowledge to use. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Objectives" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Practice reading one and multiple elements from lists\n", - "* Practice altering data in lists\n", - "* Practice adding elements and removing elements from lists" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Our initial data structure " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In the previous lesson, we had a list of top travel cities." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "> Remember to press shift+enter to run each gray block of code (including the one above). Otherwise, the variables will not be defined." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In this lesson we will work with a list of associated countries corresponding to each of the top travel cities." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "countries = ['Croatia',\n", - " 'USA',\n", - " 'Argentina',\n", - " 'Mexico',\n", - " 'USA',\n", - " 'Morocco',\n", - " 'New Mexico',\n", - " 'Finland',\n", - " 'Argentina',\n", - " 'Italy',\n", - " 'Canada',\n", - " 'South Korea']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "> Run the code in the cell above by pressing shift + enter." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Ok, so the list of countries associated with each city has been assigned to the variable `countries`. Now we will work with reading and manipulating this list." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Accessing elements from lists" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First, set the variable `italy` to be equal to the third to last element from `countries`. \n", - ">**Note:** If you see an **error** stating that `countries` is undefined, it means you must press shift+enter in the second gray box where `countries` variable is assigned." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "italy = None # 'Italy'\n", - "italy" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "> We assign the varible `italy` equal to `None`, but you should change the word `None` to code that uses the `countries` list to assign `italy` to `'Italy'`. We wrote the variable `italy` a second time, so that you can see what it equals when you run the code block. Currently, nothing is displayed below as it equals `None`, but when it's correct it will match the string which is commented out, `'Italy'`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "italy # 'Italy'" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now access the fourth element and set it equal to the variable `mexico`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mexico = None\n", - "mexico" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Notice that the second through fifth elements are all in a row and all in the Western Hemisphere. Assign that subset of elements to a variable called `kindof_neighbors`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "kindof_neighbors = None\n", - "kindof_neighbors" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Changing Elements" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Ok, now let's add a couple of countries onto this list. At the end of the list, add the country 'Malta'." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "None # add code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then add the country 'Thailand'." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "None # add code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now your list of countries should look like the following." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "countries \n", - "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'New Mexico', 'Finland', \n", - "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You may have noticed that \"New Mexico\" is included in our list of countries. That doesn't seem right. Let's change 'New Mexico' to 'USA'." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "None # add code here" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "countries \n", - "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', \n", - "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Finally, let's remove Thailand from the list. No good reason, we're acting on whimsy." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "countries = ['Croatia',\n", - " 'USA',\n", - " 'Argentina',\n", - " 'Mexico',\n", - " 'USA',\n", - " 'Morocco',\n", - " 'USA',\n", - " 'Finland',\n", - " 'Argentina',\n", - " 'Italy',\n", - " 'Canada',\n", - " 'South Korea', \n", - " 'Malta', \n", - " 'Thailand']\n", - "countries.pop() # 'Thailand'\n", - "countries\n", - "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exploring Lists with Methods" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First, use the `set` and `list` functions to return a unique list of countries. Set this list equal to the variable `unique_countries`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "unique_countries = None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "unique_countries # ['USA', 'Finland', 'Argentina', 'South Korea', 'Morocco',\n", - "#'Croatia','Mexico','Malta','Italy','Canada']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "num_of_repeats = None\n", - "num_of_repeats # 3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Summary" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "In this lesson, we had some practice with working with lists in Python. We saw how to add and remove elements from a list, as well as select specific elements. Finally, we saw how to use a different data structure to calculate the number of unique elements in the list." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.6.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} +{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists Lab "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's put this knowledge to use. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Objectives"]}, {"cell_type": "markdown", "metadata": {}, "source": ["* Practice reading one and multiple elements from lists\n", "* Practice altering data in lists\n", "* Practice adding elements and removing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Our initial data structure "]}, {"cell_type": "markdown", "metadata": {}, "source": ["In the previous lesson, we had a list of top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Remember to press shift+enter to run each gray block of code (including the one above). Otherwise, the variables will not be defined."]}, {"cell_type": "markdown", "metadata": {}, "source": ["In this lesson we will work with a list of associated countries corresponding to each of the top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'New Mexico',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Run the code in the cell above by pressing shift + enter."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so the list of countries associated with each city has been assigned to the variable `countries`. Now we will work with reading and manipulating this list."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Accessing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, set the variable `italy` to be equal to the third to last element from `countries`. \n", ">**Note:** If you see an **error** stating that `countries` is undefined, it means you must press shift+enter in the second gray box where `countries` variable is assigned."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["italy = None # 'Italy'\n", "italy"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> We assign the varible `italy` equal to `None`, but you should change the word `None` to code that uses the `countries` list to assign `italy` to `'Italy'`. We wrote the variable `italy` a second time, so that you can see what it equals when you run the code block. Currently, nothing is displayed below as it equals `None`, but when it's correct it will match the string which is commented out, `'Italy'`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["italy # 'Italy'"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now access the fourth element and set it equal to the variable `mexico`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["mexico = None\n", "mexico"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Notice that the second through fifth elements are all in a row and all in the Western Hemisphere. Assign that subset of elements to a variable called `kindof_neighbors`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["kindof_neighbors = None\n", "kindof_neighbors"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Changing Elements"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now let's add a couple of countries onto this list. At the end of the list, add the country 'Malta'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Then add the country 'Thailand'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now your list of countries should look like the following."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'New Mexico', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You may have noticed that \"New Mexico\" is included in our list of countries. That doesn't seem right. Let's change 'New Mexico' to 'USA'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = None # add code here"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Finally, let's remove Thailand from the list. No good reason, we're acting on whimsy."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'USA',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea', \n", " 'Malta', \n", " 'Thailand']\n", "countries.pop() # 'Thailand'\n", "countries\n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Exploring Lists with Methods"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, use the `set` and `list` functions to return a unique list of countries. Set this list equal to the variable `unique_countries`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["unique_countries = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["unique_countries # ['Croatia', 'Argentina', 'Canada', 'Mexico', 'Italy', \n", "#'South Korea', 'USA', 'Morocco', 'Malta', 'Finland'] Note: order of countries may be different"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["num_of_repeats = None\n", "num_of_repeats # 3"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson, we had some practice with working with lists in Python. We saw how to add and remove elements from a list, as well as select specific elements. Finally, we saw how to use a different data structure to calculate the number of unique elements in the list."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.6.6"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file From 665656aef689262d34d595903a813af0df262c26 Mon Sep 17 00:00:00 2001 From: Matt Stetz Date: Mon, 16 Sep 2019 14:30:08 -0400 Subject: [PATCH 4/5] wording --- README.md | 2 +- index.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74d3cc5c133..d9096feb542 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ### Introduction -Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's put this knowledge to use. +Ok, so now that we have a sense of how to read from and alter a list in Python, let's put this knowledge to use. ### Objectives diff --git a/index.ipynb b/index.ipynb index 9b2df0807cc..0fe247ae2dd 100644 --- a/index.ipynb +++ b/index.ipynb @@ -1 +1 @@ -{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists Lab "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from a list and alter a list in Python, let's put this knowledge to use. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Objectives"]}, {"cell_type": "markdown", "metadata": {}, "source": ["* Practice reading one and multiple elements from lists\n", "* Practice altering data in lists\n", "* Practice adding elements and removing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Our initial data structure "]}, {"cell_type": "markdown", "metadata": {}, "source": ["In the previous lesson, we had a list of top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Remember to press shift+enter to run each gray block of code (including the one above). Otherwise, the variables will not be defined."]}, {"cell_type": "markdown", "metadata": {}, "source": ["In this lesson we will work with a list of associated countries corresponding to each of the top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'New Mexico',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Run the code in the cell above by pressing shift + enter."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so the list of countries associated with each city has been assigned to the variable `countries`. Now we will work with reading and manipulating this list."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Accessing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, set the variable `italy` to be equal to the third to last element from `countries`. \n", ">**Note:** If you see an **error** stating that `countries` is undefined, it means you must press shift+enter in the second gray box where `countries` variable is assigned."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["italy = None # 'Italy'\n", "italy"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> We assign the varible `italy` equal to `None`, but you should change the word `None` to code that uses the `countries` list to assign `italy` to `'Italy'`. We wrote the variable `italy` a second time, so that you can see what it equals when you run the code block. Currently, nothing is displayed below as it equals `None`, but when it's correct it will match the string which is commented out, `'Italy'`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["italy # 'Italy'"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now access the fourth element and set it equal to the variable `mexico`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["mexico = None\n", "mexico"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Notice that the second through fifth elements are all in a row and all in the Western Hemisphere. Assign that subset of elements to a variable called `kindof_neighbors`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["kindof_neighbors = None\n", "kindof_neighbors"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Changing Elements"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now let's add a couple of countries onto this list. At the end of the list, add the country 'Malta'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Then add the country 'Thailand'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now your list of countries should look like the following."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'New Mexico', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You may have noticed that \"New Mexico\" is included in our list of countries. That doesn't seem right. Let's change 'New Mexico' to 'USA'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = None # add code here"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Finally, let's remove Thailand from the list. No good reason, we're acting on whimsy."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'USA',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea', \n", " 'Malta', \n", " 'Thailand']\n", "countries.pop() # 'Thailand'\n", "countries\n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Exploring Lists with Methods"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, use the `set` and `list` functions to return a unique list of countries. Set this list equal to the variable `unique_countries`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["unique_countries = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["unique_countries # ['Croatia', 'Argentina', 'Canada', 'Mexico', 'Italy', \n", "#'South Korea', 'USA', 'Morocco', 'Malta', 'Finland'] Note: order of countries may be different"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["num_of_repeats = None\n", "num_of_repeats # 3"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson, we had some practice with working with lists in Python. We saw how to add and remove elements from a list, as well as select specific elements. Finally, we saw how to use a different data structure to calculate the number of unique elements in the list."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.6.6"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file +{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists Lab "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from and alter a list in Python, let's put this knowledge to use. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Objectives"]}, {"cell_type": "markdown", "metadata": {}, "source": ["* Practice reading one and multiple elements from lists\n", "* Practice altering data in lists\n", "* Practice adding elements and removing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Our initial data structure "]}, {"cell_type": "markdown", "metadata": {}, "source": ["In the previous lesson, we had a list of top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Remember to press shift+enter to run each gray block of code (including the one above). Otherwise, the variables will not be defined."]}, {"cell_type": "markdown", "metadata": {}, "source": ["In this lesson we will work with a list of associated countries corresponding to each of the top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'New Mexico',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Run the code in the cell above by pressing shift + enter."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so the list of countries associated with each city has been assigned to the variable `countries`. Now we will work with reading and manipulating this list."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Accessing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, set the variable `italy` to be equal to the third to last element from `countries`. \n", ">**Note:** If you see an **error** stating that `countries` is undefined, it means you must press shift+enter in the second gray box where `countries` variable is assigned."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["italy = None # 'Italy'\n", "italy"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> We assign the varible `italy` equal to `None`, but you should change the word `None` to code that uses the `countries` list to assign `italy` to `'Italy'`. We wrote the variable `italy` a second time, so that you can see what it equals when you run the code block. Currently, nothing is displayed below as it equals `None`, but when it's correct it will match the string which is commented out, `'Italy'`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["italy # 'Italy'"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now access the fourth element and set it equal to the variable `mexico`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["mexico = None\n", "mexico"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Notice that the second through fifth elements are all in a row and all in the Western Hemisphere. Assign that subset of elements to a variable called `kindof_neighbors`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["kindof_neighbors = None\n", "kindof_neighbors"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Changing Elements"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now let's add a couple of countries onto this list. At the end of the list, add the country 'Malta'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Then add the country 'Thailand'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now your list of countries should look like the following."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'New Mexico', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You may have noticed that \"New Mexico\" is included in our list of countries. That doesn't seem right. Let's change 'New Mexico' to 'USA'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = None # add code here"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Finally, let's remove Thailand from the list. No good reason, we're acting on whimsy."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'USA',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea', \n", " 'Malta', \n", " 'Thailand']\n", "countries.pop() # 'Thailand'\n", "countries\n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Exploring Lists with Methods"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, use the `set` and `list` functions to return a unique list of countries. Set this list equal to the variable `unique_countries`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["unique_countries = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["unique_countries # ['Croatia', 'Argentina', 'Canada', 'Mexico', 'Italy', \n", "#'South Korea', 'USA', 'Morocco', 'Malta', 'Finland'] Note: order of countries may be different"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["num_of_repeats = None\n", "num_of_repeats # 3"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson, we had some practice with working with lists in Python. We saw how to add and remove elements from a list, as well as select specific elements. Finally, we saw how to use a different data structure to calculate the number of unique elements in the list."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.7.3"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file From f10b03762354d09ec0ee34fbb31abff7761b3360 Mon Sep 17 00:00:00 2001 From: Matt Stetz Date: Tue, 17 Sep 2019 09:43:43 -0400 Subject: [PATCH 5/5] wording --- README.md | 2 +- index.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9096feb542..25a3fe936ce 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ### Introduction -Ok, so now that we have a sense of how to read from and alter a list in Python, let's put this knowledge to use. +Ok, so now that we have a sense of how to read and alter a list in Python, let's put this knowledge to use. ### Objectives diff --git a/index.ipynb b/index.ipynb index 0fe247ae2dd..6ac52170c07 100644 --- a/index.ipynb +++ b/index.ipynb @@ -1 +1 @@ -{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists Lab "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read from and alter a list in Python, let's put this knowledge to use. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Objectives"]}, {"cell_type": "markdown", "metadata": {}, "source": ["* Practice reading one and multiple elements from lists\n", "* Practice altering data in lists\n", "* Practice adding elements and removing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Our initial data structure "]}, {"cell_type": "markdown", "metadata": {}, "source": ["In the previous lesson, we had a list of top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Remember to press shift+enter to run each gray block of code (including the one above). Otherwise, the variables will not be defined."]}, {"cell_type": "markdown", "metadata": {}, "source": ["In this lesson we will work with a list of associated countries corresponding to each of the top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'New Mexico',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Run the code in the cell above by pressing shift + enter."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so the list of countries associated with each city has been assigned to the variable `countries`. Now we will work with reading and manipulating this list."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Accessing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, set the variable `italy` to be equal to the third to last element from `countries`. \n", ">**Note:** If you see an **error** stating that `countries` is undefined, it means you must press shift+enter in the second gray box where `countries` variable is assigned."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["italy = None # 'Italy'\n", "italy"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> We assign the varible `italy` equal to `None`, but you should change the word `None` to code that uses the `countries` list to assign `italy` to `'Italy'`. We wrote the variable `italy` a second time, so that you can see what it equals when you run the code block. Currently, nothing is displayed below as it equals `None`, but when it's correct it will match the string which is commented out, `'Italy'`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["italy # 'Italy'"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now access the fourth element and set it equal to the variable `mexico`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["mexico = None\n", "mexico"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Notice that the second through fifth elements are all in a row and all in the Western Hemisphere. Assign that subset of elements to a variable called `kindof_neighbors`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["kindof_neighbors = None\n", "kindof_neighbors"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Changing Elements"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now let's add a couple of countries onto this list. At the end of the list, add the country 'Malta'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Then add the country 'Thailand'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now your list of countries should look like the following."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'New Mexico', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You may have noticed that \"New Mexico\" is included in our list of countries. That doesn't seem right. Let's change 'New Mexico' to 'USA'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = None # add code here"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Finally, let's remove Thailand from the list. No good reason, we're acting on whimsy."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'USA',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea', \n", " 'Malta', \n", " 'Thailand']\n", "countries.pop() # 'Thailand'\n", "countries\n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Exploring Lists with Methods"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, use the `set` and `list` functions to return a unique list of countries. Set this list equal to the variable `unique_countries`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["unique_countries = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["unique_countries # ['Croatia', 'Argentina', 'Canada', 'Mexico', 'Italy', \n", "#'South Korea', 'USA', 'Morocco', 'Malta', 'Finland'] Note: order of countries may be different"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["num_of_repeats = None\n", "num_of_repeats # 3"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson, we had some practice with working with lists in Python. We saw how to add and remove elements from a list, as well as select specific elements. Finally, we saw how to use a different data structure to calculate the number of unique elements in the list."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.7.3"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file +{"cells": [{"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["# Lists Lab "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Introduction"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so now that we have a sense of how to read and alter a list in Python, let's put this knowledge to use. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Objectives"]}, {"cell_type": "markdown", "metadata": {}, "source": ["* Practice reading one and multiple elements from lists\n", "* Practice altering data in lists\n", "* Practice adding elements and removing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Our initial data structure "]}, {"cell_type": "markdown", "metadata": {}, "source": ["In the previous lesson, we had a list of top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Remember to press shift+enter to run each gray block of code (including the one above). Otherwise, the variables will not be defined."]}, {"cell_type": "markdown", "metadata": {}, "source": ["In this lesson we will work with a list of associated countries corresponding to each of the top travel cities."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'New Mexico',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> Run the code in the cell above by pressing shift + enter."]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, so the list of countries associated with each city has been assigned to the variable `countries`. Now we will work with reading and manipulating this list."]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Accessing elements from lists"]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, set the variable `italy` to be equal to the third to last element from `countries`. \n", ">**Note:** If you see an **error** stating that `countries` is undefined, it means you must press shift+enter in the second gray box where `countries` variable is assigned."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["italy = None # 'Italy'\n", "italy"]}, {"cell_type": "markdown", "metadata": {}, "source": ["> We assign the varible `italy` equal to `None`, but you should change the word `None` to code that uses the `countries` list to assign `italy` to `'Italy'`. We wrote the variable `italy` a second time, so that you can see what it equals when you run the code block. Currently, nothing is displayed below as it equals `None`, but when it's correct it will match the string which is commented out, `'Italy'`."]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["italy # 'Italy'"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now access the fourth element and set it equal to the variable `mexico`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["mexico = None\n", "mexico"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Notice that the second through fifth elements are all in a row and all in the Western Hemisphere. Assign that subset of elements to a variable called `kindof_neighbors`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["kindof_neighbors = None\n", "kindof_neighbors"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Changing Elements"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now let's add a couple of countries onto this list. At the end of the list, add the country 'Malta'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Then add the country 'Thailand'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["None # add code here"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now your list of countries should look like the following."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'New Mexico', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You may have noticed that \"New Mexico\" is included in our list of countries. That doesn't seem right. Let's change 'New Mexico' to 'USA'."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = None # add code here"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries \n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', \n", "# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Finally, let's remove Thailand from the list. No good reason, we're acting on whimsy."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["countries = ['Croatia',\n", " 'USA',\n", " 'Argentina',\n", " 'Mexico',\n", " 'USA',\n", " 'Morocco',\n", " 'USA',\n", " 'Finland',\n", " 'Argentina',\n", " 'Italy',\n", " 'Canada',\n", " 'South Korea', \n", " 'Malta', \n", " 'Thailand']\n", "countries.pop() # 'Thailand'\n", "countries\n", "# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Exploring Lists with Methods"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list. "]}, {"cell_type": "markdown", "metadata": {}, "source": ["First, use the `set` and `list` functions to return a unique list of countries. Set this list equal to the variable `unique_countries`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["unique_countries = None"]}, {"cell_type": "code", "execution_count": null, "metadata": {"scrolled": true}, "outputs": [], "source": ["unique_countries # ['Croatia', 'Argentina', 'Canada', 'Mexico', 'Italy', \n", "#'South Korea', 'USA', 'Morocco', 'Malta', 'Finland'] Note: order of countries may be different"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Now the number of repeat countries should be the number of countries minus the number of unique countries. So use the `len` function on both `unique_countries` and `countries` to calculate this and assign the result to the variable `num_of_repeats`."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["num_of_repeats = None\n", "num_of_repeats # 3"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Summary"]}, {"cell_type": "markdown", "metadata": {"collapsed": true}, "source": ["In this lesson, we had some practice with working with lists in Python. We saw how to add and remove elements from a list, as well as select specific elements. Finally, we saw how to use a different data structure to calculate the number of unique elements in the list."]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.7.3"}}, "nbformat": 4, "nbformat_minor": 2} \ No newline at end of file