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
Copy file name to clipboardExpand all lines: README.md
+7-25Lines changed: 7 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
2
2
# Introduction to lists
3
3
4
-
So far we have worked with individual pieces of data like the string `hello`, then with variables we saw how to give this data a name with variables. Well in this lesson, we'll see how we can group data together with lists.
4
+
So far we have worked with individual pieces of data like the string `hello`, then with variables we saw how to give this data a name. Well, in this lesson, we'll see how we can group data together with lists.
5
5
6
6
### Creating a list
7
7
8
-
A list is our first form of a collection. A collection is just a way of grouping data together, and lists certainly accomplish this. For example, let's consider the top cities to travel to according to Travel and Leisure. We'll see it below, but we must stay focused on Python and data!
8
+
A list is our first form of a collection. A collection is just a way of grouping data together, and lists certainly accomplish this. For example, let's consider the top cities to travel to according to Travel and Leisure. We'll see it below, but we must stay focused on Python and data! Here is how we are used to seeing a list of travel locations in a document or on a website.
9
9
10
10
#### Travel Locations
11
11
1. Solta
@@ -21,7 +21,7 @@ A list is our first form of a collection. A collection is just a way of groupin
21
21
11. Toronto
22
22
12. Pyeongchang
23
23
24
-
Ok, and this is how we express this in Python.
24
+
And here is how that same list looks in Python:
25
25
26
26
27
27
```python
@@ -46,7 +46,7 @@ Ok, and this is how we express this in Python.
46
46
47
47
48
48
49
-
So we indicate that we are initializing a `list` by placing a bracket, `[` (located above of the return key), and end the list with a closing bracket `']'`. To separate each item in the list, called an element, we place a comma.
49
+
So we indicate that we are initializing a `list` by placing a bracket, `[`, and end the list with a closing bracket `']'`. To separate each list item, called an element, we place a comma.
Now our `top_travel_cities` list is contains multiple elements. And just like we numbered the elements of a list with text:
111
+
Now our `top_travel_cities` list contains multiple elements. And just like we numbered the elements of a list with text:
112
112
113
113
1. Solta
114
114
2. Greenville
@@ -167,7 +167,7 @@ top_travel_cities[2]
167
167
168
168
169
169
170
-
How would we access the last element, well we could count all of the elements in the list, and `Pyeongchang` would just be one less than that. Or we can ask Python to start from the back in move back one.
170
+
How would we access the last element? Well, we could count all of the elements in the list, and `Pyeongchang` would just be one less than that. Or we can ask Python to start from the back in move back one.
The `pop` method is available to call on any list, and removes the last element from the list. As you can see below, calling `pop` removed our last element.
Copy file name to clipboardExpand all lines: index.ipynb
+15-32Lines changed: 15 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@
13
13
"cell_type": "markdown",
14
14
"metadata": {},
15
15
"source": [
16
-
"So far we have worked with individual pieces of data like the string `hello`, then with variables we saw how to give this data a name with variables. Well in this lesson, we'll see how we can group data together with lists. "
16
+
"So far we have worked with individual pieces of data like the string `hello`, then with variables we saw how to give this data a name. Well, in this lesson, we'll see how we can group data together with lists. "
17
17
]
18
18
},
19
19
{
@@ -27,7 +27,7 @@
27
27
"cell_type": "markdown",
28
28
"metadata": {},
29
29
"source": [
30
-
"A list is our first form of a collection. A collection is just a way of grouping data together, and lists certainly accomplish this. For example, let's consider the top cities to travel to according to Travel and Leisure. We'll see it below, but we must stay focused on Python and data! "
30
+
"A list is our first form of a collection. A collection is just a way of grouping data together, and lists certainly accomplish this. For example, let's consider the top cities to travel to according to Travel and Leisure. We'll see it below, but we must stay focused on Python and data! Here is how we are used to seeing a list of travel locations in a document or on a website."
31
31
]
32
32
},
33
33
{
@@ -53,7 +53,7 @@
53
53
"cell_type": "markdown",
54
54
"metadata": {},
55
55
"source": [
56
-
"Ok, and this is how we express this in Python."
56
+
"And here is how that same list looks in Python:"
57
57
]
58
58
},
59
59
{
@@ -91,7 +91,7 @@
91
91
"cell_type": "markdown",
92
92
"metadata": {},
93
93
"source": [
94
-
"So we indicate that we are initializing a `list` by placing a bracket, `[` (located above of the return key), and end the list with a closing bracket `']'`. To separate each item in the list, called an element, we place a comma."
94
+
"So we indicate that we are initializing a `list` by placing a bracket, `[`, and end the list with a closing bracket `']'`. To separate each list item, called an element, we place a comma."
95
95
]
96
96
},
97
97
{
@@ -196,7 +196,7 @@
196
196
"cell_type": "markdown",
197
197
"metadata": {},
198
198
"source": [
199
-
"Now our `top_travel_cities` list is contains multiple elements. And just like we numbered the elements of a list with text:\n",
199
+
"Now our `top_travel_cities` list contains multiple elements. And just like we numbered the elements of a list with text:\n",
200
200
"\n",
201
201
"1. Solta\n",
202
202
"2. Greenville\n",
@@ -294,7 +294,7 @@
294
294
"cell_type": "markdown",
295
295
"metadata": {},
296
296
"source": [
297
-
"How would we access the last element, well we could count all of the elements in the list, and `Pyeongchang` would just be one less than that. Or we can ask Python to start from the back in move back one."
297
+
"How would we access the last element? Well, we could count all of the elements in the list, and `Pyeongchang` would just be one less than that. Or we can ask Python to start from the back in move back one."
298
298
]
299
299
},
300
300
{
@@ -724,38 +724,21 @@
724
724
},
725
725
{
726
726
"cell_type": "code",
727
-
"execution_count": 97,
727
+
"execution_count": null,
728
728
"metadata": {},
729
-
"outputs": [
730
-
{
731
-
"data": {
732
-
"text/plain": [
733
-
"['Solta',\n",
734
-
" 'Greenville',\n",
735
-
" 'Buenos Aires',\n",
736
-
" 'Los Cabos',\n",
737
-
" 'Walla Walla Valley',\n",
738
-
" 'Marakesh',\n",
739
-
" 'Albuquerque',\n",
740
-
" 'Archipelago Sea',\n",
741
-
" 'Iguazu Falls',\n",
742
-
" 'Salina Island',\n",
743
-
" 'Toronto',\n",
744
-
" 'Pyeongchang',\n",
745
-
" 'San Antonio',\n",
746
-
" 'San Antonio']"
747
-
]
748
-
},
749
-
"execution_count": 97,
750
-
"metadata": {},
751
-
"output_type": "execute_result"
752
-
}
753
-
],
729
+
"outputs": [],
754
730
"source": [
755
731
"top_travel_cities.append('San Antonio')\n",
756
732
"top_travel_cities"
757
733
]
758
734
},
735
+
{
736
+
"cell_type": "markdown",
737
+
"metadata": {},
738
+
"source": [
739
+
"The `pop` method is available to call on any list, and removes the last element from the list. As you can see below, calling `pop` removed our last element."
0 commit comments