Skip to content

Commit 0689588

Browse files
committed
add about preference for lists
1 parent d6756f4 commit 0689588

File tree

1 file changed

+55
-46
lines changed

1 file changed

+55
-46
lines changed

index.ipynb

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"cell_type": "markdown",
1414
"metadata": {},
1515
"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. 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. "
1717
]
1818
},
1919
{
@@ -27,7 +27,7 @@
2727
"cell_type": "markdown",
2828
"metadata": {},
2929
"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! Here is how we are used to seeing a list of travel locations in a document or on a website."
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 for travel according to the magazine Travel and Leisure. Here is how we are used to seeing a list of travel locations in a document or on a website."
3131
]
3232
},
3333
{
@@ -53,7 +53,7 @@
5353
"cell_type": "markdown",
5454
"metadata": {},
5555
"source": [
56-
"And here is how that same list looks in Python:"
56+
"And here what that same list looks like in Python:"
5757
]
5858
},
5959
{
@@ -91,7 +91,7 @@
9191
"cell_type": "markdown",
9292
"metadata": {},
9393
"source": [
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."
94+
"So we indicate that we are initializing a `list` by placing an opening bracket, `[`, and end the list with a closing bracket `]`. To separate each list item, called an element, we place a comma."
9595
]
9696
},
9797
{
@@ -129,12 +129,12 @@
129129
"cell_type": "markdown",
130130
"metadata": {},
131131
"source": [
132-
"And of course, we can set each list equal to variable so that we can name each list."
132+
"And of course, we can set each list equal to variable so that we can name and retrieve our list."
133133
]
134134
},
135135
{
136136
"cell_type": "code",
137-
"execution_count": 77,
137+
"execution_count": 1,
138138
"metadata": {
139139
"collapsed": true
140140
},
@@ -145,38 +145,16 @@
145145
},
146146
{
147147
"cell_type": "code",
148-
"execution_count": 78,
148+
"execution_count": null,
149149
"metadata": {},
150-
"outputs": [
151-
{
152-
"data": {
153-
"text/plain": [
154-
"['Solta',\n",
155-
" 'Greenville',\n",
156-
" 'Buenos Aires',\n",
157-
" 'Los Cabos',\n",
158-
" 'Walla Walla Valley',\n",
159-
" 'Marakesh',\n",
160-
" 'Albuquerque',\n",
161-
" 'Archipelago Sea',\n",
162-
" 'Iguazu Falls',\n",
163-
" 'Salina Island',\n",
164-
" 'Toronto',\n",
165-
" 'Pyeongchang']"
166-
]
167-
},
168-
"execution_count": 78,
169-
"metadata": {},
170-
"output_type": "execute_result"
171-
}
172-
],
150+
"outputs": [],
173151
"source": [
174152
"top_travel_cities"
175153
]
176154
},
177155
{
178156
"cell_type": "code",
179-
"execution_count": 79,
157+
"execution_count": 2,
180158
"metadata": {
181159
"collapsed": true
182160
},
@@ -196,7 +174,7 @@
196174
"cell_type": "markdown",
197175
"metadata": {},
198176
"source": [
199-
"Now our `top_travel_cities` list contains multiple elements. And just like we numbered the elements of a list with text:\n",
177+
"Now our `top_travel_cities` list contains multiple elements. And just like we are used to list elements having a rank or number associated with them...\n",
200178
"\n",
201179
"1. Solta\n",
202180
"2. Greenville\n",
@@ -207,7 +185,7 @@
207185
"cell_type": "markdown",
208186
"metadata": {},
209187
"source": [
210-
"A list in Python also assigns a number to each element."
188+
"...a list in Python also assigns a number to each element."
211189
]
212190
},
213191
{
@@ -265,9 +243,9 @@
265243
"cell_type": "markdown",
266244
"metadata": {},
267245
"source": [
268-
"In the above line we are referencing a list and then using the brackets to access specific elements of our list. We access elements in a list with the `index`, and there is a separate index for each element in the list. It begins at the number zero, increases for every element thereafter.\n",
246+
"In the above line we are referencing a list and then using the brackets to access a specific element of our list, the first element. We access elements in a list with the `index`, and there is a separate index for each element in the list. It begins at the number zero, increases for every element thereafter.\n",
269247
"\n",
270-
"So to access the second element we write `top_travel_cities[1]`, and the third element is `top_travel_cities[2]`:"
248+
"So to access the second element we write `top_travel_cities[1]`, and the third element is `top_travel_cities[2]`."
271249
]
272250
},
273251
{
@@ -667,7 +645,7 @@
667645
},
668646
{
669647
"cell_type": "code",
670-
"execution_count": 95,
648+
"execution_count": 5,
671649
"metadata": {
672650
"collapsed": true
673651
},
@@ -685,7 +663,7 @@
685663
},
686664
{
687665
"cell_type": "code",
688-
"execution_count": 96,
666+
"execution_count": 8,
689667
"metadata": {},
690668
"outputs": [
691669
{
@@ -706,7 +684,7 @@
706684
" 'San Antonio']"
707685
]
708686
},
709-
"execution_count": 96,
687+
"execution_count": 8,
710688
"metadata": {},
711689
"output_type": "execute_result"
712690
}
@@ -719,14 +697,38 @@
719697
"cell_type": "markdown",
720698
"metadata": {},
721699
"source": [
722-
"You will see 'San Antonio' included in the list. So note that unlike slice, `append` is destructive. That is, it changes our underlying data structure. Every time we execute the `append` method, another element is added to our list. Now what if we accidentally add 'San Antonio' a second time to our list."
700+
"You will see that 'San Antonio' has been added to the list. So note that unlike slice, `append` is destructive. That is, it changes our underlying data structure. Every time we execute the `append` method, another element is added to our list. Now what if we accidentally add 'San Antonio' a second time to our list."
723701
]
724702
},
725703
{
726704
"cell_type": "code",
727-
"execution_count": null,
705+
"execution_count": 9,
728706
"metadata": {},
729-
"outputs": [],
707+
"outputs": [
708+
{
709+
"data": {
710+
"text/plain": [
711+
"['Solta',\n",
712+
" 'Greenville',\n",
713+
" 'Buenos Aires',\n",
714+
" 'Los Cabos',\n",
715+
" 'Walla Walla Valley',\n",
716+
" 'Marakesh',\n",
717+
" 'Albuquerque',\n",
718+
" 'Archipelago Sea',\n",
719+
" 'Iguazu Falls',\n",
720+
" 'Salina Island',\n",
721+
" 'Toronto',\n",
722+
" 'Pyeongchang',\n",
723+
" 'San Antonio',\n",
724+
" 'San Antonio']"
725+
]
726+
},
727+
"execution_count": 9,
728+
"metadata": {},
729+
"output_type": "execute_result"
730+
}
731+
],
730732
"source": [
731733
"top_travel_cities.append('San Antonio')\n",
732734
"top_travel_cities"
@@ -736,12 +738,12 @@
736738
"cell_type": "markdown",
737739
"metadata": {},
738740
"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."
741+
"If you press shift+enter on the above line of code, we will have `'San Antonio'` as the last two elements of the list. Luckily, we have the `pop` method to remove one of them. 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."
740742
]
741743
},
742744
{
743745
"cell_type": "code",
744-
"execution_count": 98,
746+
"execution_count": 10,
745747
"metadata": {},
746748
"outputs": [
747749
{
@@ -750,7 +752,7 @@
750752
"'San Antonio'"
751753
]
752754
},
753-
"execution_count": 98,
755+
"execution_count": 10,
754756
"metadata": {},
755757
"output_type": "execute_result"
756758
}
@@ -768,7 +770,7 @@
768770
},
769771
{
770772
"cell_type": "code",
771-
"execution_count": 99,
773+
"execution_count": 11,
772774
"metadata": {},
773775
"outputs": [
774776
{
@@ -777,7 +779,7 @@
777779
"'Walla Walla Valley'"
778780
]
779781
},
780-
"execution_count": 99,
782+
"execution_count": 11,
781783
"metadata": {},
782784
"output_type": "execute_result"
783785
}
@@ -1197,6 +1199,13 @@
11971199
"top_travel_cities"
11981200
]
11991201
},
1202+
{
1203+
"cell_type": "markdown",
1204+
"metadata": {},
1205+
"source": [
1206+
"> For most purposes, Python developers prefer to work with `lists` as opposed to sets, as `lists` are generally easier to manipulate, as you will see in future lessons."
1207+
]
1208+
},
12001209
{
12011210
"cell_type": "markdown",
12021211
"metadata": {},

0 commit comments

Comments
 (0)