You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, set the variable `italy` to be equal to the third to last element from `countries`.
50
66
>**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.
51
67
@@ -55,13 +71,21 @@ italy = None # 'Italy'
55
71
italy
56
72
```
57
73
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'`.
59
75
60
76
61
77
```python
62
78
italy # 'Italy'
63
79
```
64
80
81
+
82
+
```python
83
+
%%unittest_testcase
84
+
85
+
deftest_italy(self):
86
+
self.assertEqual(italy, 'Italy')
87
+
```
88
+
65
89
Now access the fourth element and set it equal to the variable `mexico`.
66
90
67
91
@@ -70,6 +94,14 @@ mexico = None
70
94
mexico
71
95
```
72
96
97
+
98
+
```python
99
+
%%unittest_testcase
100
+
101
+
deftest_mexico(self):
102
+
self.assertEqual(mexico, 'Mexico')
103
+
```
104
+
73
105
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`.
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
166
256
num_of_repeats # 3
167
257
```
168
258
259
+
260
+
```python
261
+
%%unittest_testcase
262
+
263
+
deftest_num_of_repeats(self):
264
+
self.assertEqual(num_of_repeats, 3)
265
+
```
266
+
169
267
### Summary
170
268
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