Skip to content

Commit f552383

Browse files
committed
added updated index.ipynb from ipython-lists-lab and updating readme
1 parent 7434047 commit f552383

File tree

2 files changed

+291
-48
lines changed

2 files changed

+291
-48
lines changed

README.md

Lines changed: 106 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Lists Lab
2+
# UI Testing Lists Lab
33

44
### Introduction
55

@@ -22,8 +22,6 @@ top_travel_cities = ['Solta', 'Greenville', 'Buenos Aires', 'Los Cabos', 'Walla
2222

2323
> 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 associated countries corresponding to each of the top travel cities.
26-
2725

2826
```python
2927
countries = ['Croatia',
@@ -46,6 +44,24 @@ Ok, so the list of countries associated with each city has been assigned to the
4644

4745
### Accessing elements from lists
4846

47+
For the tests in this lab to work, please run the following two cells.
48+
49+
50+
```python
51+
!pip install ipython_unittest
52+
```
53+
54+
Collecting ipython_unittest
55+
Downloading ipython_unittest-0.3.1-py2.py3-none-any.whl
56+
Installing collected packages: ipython-unittest
57+
Successfully installed ipython-unittest-0.3.1
58+
59+
60+
61+
```python
62+
%load_ext ipython_unittest
63+
```
64+
4965
First, set the variable `italy` to be equal to the third to last element from `countries`.
5066
>**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.
5167
@@ -55,13 +71,21 @@ italy = None # 'Italy'
5571
italy
5672
```
5773

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'`.
74+
> 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'`.
5975
6076

6177
```python
6278
italy # 'Italy'
6379
```
6480

81+
82+
```python
83+
%%unittest_testcase
84+
85+
def test_italy(self):
86+
self.assertEqual(italy, 'Italy')
87+
```
88+
6589
Now access the fourth element and set it equal to the variable `mexico`.
6690

6791

@@ -70,6 +94,14 @@ mexico = None
7094
mexico
7195
```
7296

97+
98+
```python
99+
%%unittest_testcase
100+
101+
def test_mexico(self):
102+
self.assertEqual(mexico, 'Mexico')
103+
```
104+
73105
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`.
74106

75107

@@ -78,6 +110,14 @@ kindof_neighbors = None
78110
kindof_neighbors
79111
```
80112

113+
114+
```python
115+
%%unittest_testcase
116+
117+
def test_kindof_neighbors(self):
118+
self.assertEqual(kindof_neighbors, ['USA', 'Argentina', 'Mexico', 'USA'])
119+
```
120+
81121
### Changing Elements
82122

83123
Ok, now let's add a couple of countries onto this list. At the end of the list, add the country 'Malta'.
@@ -103,6 +143,14 @@ countries
103143
# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']
104144
```
105145

146+
147+
```python
148+
%%unittest_testcase
149+
150+
def test_countries(self):
151+
self.assertItemsEqual(countries, ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'New Mexico', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand'])
152+
```
153+
106154
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'.
107155

108156

@@ -117,6 +165,14 @@ countries
117165
# 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta', 'Thailand']
118166
```
119167

168+
169+
```python
170+
%%unittest_testcase
171+
172+
def test_countries_with_usa(self):
173+
self.assertNotIn('New Mexico', countries)
174+
```
175+
120176
Finally, let's remove Thailand from the list. No good reason, we're acting on whimsy.
121177

122178

@@ -140,6 +196,33 @@ countries
140196
# ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Morocco', 'USA', 'Finland', 'Argentina', 'Italy', 'Canada', 'South Korea', 'Malta']
141197
```
142198

199+
200+
201+
202+
['Croatia',
203+
'USA',
204+
'Argentina',
205+
'Mexico',
206+
'USA',
207+
'Morocco',
208+
'USA',
209+
'Finland',
210+
'Argentina',
211+
'Italy',
212+
'Canada',
213+
'South Korea',
214+
'Malta']
215+
216+
217+
218+
219+
```python
220+
%%unittest_testcase
221+
222+
def test_countries_with_usa(self):
223+
self.assertNotIn('Thailand', countries)
224+
```
225+
143226
### Exploring Lists with Methods
144227

145228
Ok, now we notice that some countries are mentioned more than once. Let's see how many repeat countries are on this list.
@@ -153,9 +236,16 @@ unique_countries = None
153236

154237

155238
```python
156-
unique_countries
157-
# ['USA', 'South Korea', 'Morocco', 'Finland', 'Italy',
158-
# 'Mexico', 'Argentina', 'Malta', 'Croatia', 'New Mexico', 'Canada']
239+
unique_countries # ['Canada', 'Italy', 'USA', 'Mexico', 'Finland',
240+
#'Malta', 'Morocco', 'Croatia', 'Argentina', 'South Korea']
241+
```
242+
243+
244+
```python
245+
%%unittest_testcase
246+
247+
def test_unique_countries(self):
248+
self.assertItemsEqual(unique_countries, ['USA', 'South Korea', 'Morocco', 'Finland', 'Italy', 'Mexico', 'Argentina', 'Malta', 'Croatia', 'Canada'])
159249
```
160250

161251
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`.
@@ -166,6 +256,14 @@ num_of_repeats = None
166256
num_of_repeats # 3
167257
```
168258

259+
260+
```python
261+
%%unittest_testcase
262+
263+
def test_num_of_repeats(self):
264+
self.assertEqual(num_of_repeats, 3)
265+
```
266+
169267
### Summary
170268

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.
269+
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.

0 commit comments

Comments
 (0)