Skip to content

Commit 635f0c0

Browse files
committed
updated readme and added tests
1 parent 93912b3 commit 635f0c0

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
### Introduction
55

6-
Ok, so now that we have gotten a sense of how to read from a list and alter a list in Python, let's put this knowledge to practice.
6+
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.
77

88
### Objectives
99

1010
* Practice reading one and multiple elements from lists
1111
* Practice altering data in lists
12-
* Practice add elements and removing elements from lists
12+
* Practice adding elements and removing elements from lists
1313

1414
### Our initial data structure
1515

@@ -20,9 +20,9 @@ In the previous lesson, we had a list of top travel cities.
2020
top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla Walla Valley', 'Marakesh', 'Albuquerque', 'Archipelago Sea', 'Iguazu Falls', 'Salina Island', 'Toronto', 'Pyeongchang']
2121
```
2222

23-
> Remember to press shift enter to run each gray block of code.
23+
> Remember to press shift+enter to run each gray block of code (including the one above). Otherwise, the variables will not be defined.
2424
25-
In this lesson we can work with a list of each associated countries for each of those travel cities.
25+
In this lesson we can work with a list of associated countries corresponding to each of the top travel cities.
2626

2727

2828
```python
@@ -40,19 +40,22 @@ countries = ['Croatia',
4040
'South Korea']
4141
```
4242

43+
> Run the code in the cell above by pressing shift + enter.
44+
4345
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.
4446

4547
### Accessing elements from lists
4648

47-
First, access the third to last element from `countries` and set it equal to the variable `italy`.
49+
First, set the variable `italy` to be equal to the third to last element from `countries`.
50+
>**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.
4851
4952

5053
```python
5154
italy = None # 'Italy'
5255
italy
5356
```
5457

55-
> 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'`.
58+
> We assign the variable `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'`.
5659
5760

5861
```python
@@ -150,7 +153,8 @@ unique_countries = None
150153

151154

152155
```python
153-
unique_countries # ['USA', 'South Korea', 'Morocco', 'Finland', 'Italy',
156+
unique_countries
157+
# ['USA', 'South Korea', 'Morocco', 'Finland', 'Italy',
154158
# 'Mexico', 'Argentina', 'Malta', 'Croatia', 'New Mexico', 'Canada']
155159
```
156160

@@ -164,4 +168,4 @@ num_of_repeats # 3
164168

165169
### Summary
166170

167-
In this section we saw how to get our data from the outside world and into Python. The purpose isn't to understand all of this code right now, but rather to see how easily we can start working with outside data. As we become better at Python, the usefulness of taking data and operating on it in code rather than a spreadsheet will become more apparent. But that doesn't mean we can't get step outside of Python sandbox now. It's not too difficult to take some data we may already have, and begin to use it with Python. In the next section, we'll use a lab to get data from excel and work with lists.
171+
In this lesson, we practiced 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 unique elements in the list.

index.ipynb

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
{
5757
"cell_type": "code",
58-
"execution_count": 1,
58+
"execution_count": 4,
5959
"metadata": {
6060
"collapsed": true
6161
},
@@ -80,7 +80,7 @@
8080
},
8181
{
8282
"cell_type": "code",
83-
"execution_count": 2,
83+
"execution_count": 5,
8484
"metadata": {
8585
"collapsed": true
8686
},
@@ -131,7 +131,7 @@
131131
},
132132
{
133133
"cell_type": "code",
134-
"execution_count": 5,
134+
"execution_count": 6,
135135
"metadata": {
136136
"collapsed": true
137137
},
@@ -150,7 +150,7 @@
150150
},
151151
{
152152
"cell_type": "code",
153-
"execution_count": 19,
153+
"execution_count": 7,
154154
"metadata": {
155155
"collapsed": true
156156
},
@@ -168,7 +168,7 @@
168168
},
169169
{
170170
"cell_type": "code",
171-
"execution_count": 20,
171+
"execution_count": 8,
172172
"metadata": {
173173
"collapsed": true
174174
},
@@ -187,7 +187,7 @@
187187
},
188188
{
189189
"cell_type": "code",
190-
"execution_count": 21,
190+
"execution_count": 9,
191191
"metadata": {
192192
"collapsed": true
193193
},
@@ -348,7 +348,7 @@
348348
},
349349
{
350350
"cell_type": "code",
351-
"execution_count": 32,
351+
"execution_count": 10,
352352
"metadata": {
353353
"collapsed": true
354354
},
@@ -359,13 +359,14 @@
359359
},
360360
{
361361
"cell_type": "code",
362-
"execution_count": 33,
362+
"execution_count": 11,
363363
"metadata": {
364364
"collapsed": true
365365
},
366366
"outputs": [],
367367
"source": [
368-
"unique_countries # ['USA', 'South Korea', 'Morocco', 'Finland', 'Italy', \n",
368+
"unique_countries \n",
369+
"# ['USA', 'South Korea', 'Morocco', 'Finland', 'Italy', \n",
369370
"# 'Mexico', 'Argentina', 'Malta', 'Croatia', 'New Mexico', 'Canada']"
370371
]
371372
},
@@ -378,7 +379,7 @@
378379
},
379380
{
380381
"cell_type": "code",
381-
"execution_count": 31,
382+
"execution_count": 12,
382383
"metadata": {
383384
"collapsed": true
384385
},
@@ -401,27 +402,27 @@
401402
"collapsed": true
402403
},
403404
"source": [
404-
"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 unique elements in the list."
405+
"In this lesson, we practiced 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 unique elements in the list."
405406
]
406407
}
407408
],
408409
"metadata": {
409410
"kernelspec": {
410-
"display_name": "Python 3",
411+
"display_name": "Python 2",
411412
"language": "python",
412-
"name": "python3"
413+
"name": "python2"
413414
},
414415
"language_info": {
415416
"codemirror_mode": {
416417
"name": "ipython",
417-
"version": 3
418+
"version": 2
418419
},
419420
"file_extension": ".py",
420421
"mimetype": "text/x-python",
421422
"name": "python",
422423
"nbconvert_exporter": "python",
423-
"pygments_lexer": "ipython3",
424-
"version": "3.6.1"
424+
"pygments_lexer": "ipython2",
425+
"version": "2.7.14"
425426
}
426427
},
427428
"nbformat": 4,

test/index_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest2 as unittest
2+
from ipynb.fs.full.index import *
3+
4+
class TestPythonLists(unittest.TestCase):
5+
6+
def test_italy(self):
7+
self.assertEqual(italy, 'Italy')
8+
9+
def test_mexico(self):
10+
self.assertEqual(mexico, 'Mexico')
11+
12+
def test_kindof_neighbors(self):
13+
self.assertEqual(kindof_neighbors, ['USA', 'Argentina', 'Mexico', 'USA'])
14+
15+
def test_malta_presence(self):
16+
self.assertIn('Malta', countries)
17+
18+
def test_new_mexico_presence(self):
19+
self.assertNotIn('New Mexico', countries)
20+
21+
def test_unique_countries(self):
22+
self.assertItemsEqual(['Argentina', 'Canada', 'Croatia', 'Finland', 'Italy', 'Malta', 'Mexico', 'Morocco', 'South Korea', 'USA'], unique_countries)
23+
24+
def test_num_repeats(self):
25+
self.assertEqual(num_of_repeats, 3)

0 commit comments

Comments
 (0)