Skip to content

Commit 6d1b847

Browse files
committed
fixed small typos
1 parent 0689588 commit 6d1b847

File tree

2 files changed

+182
-138
lines changed

2 files changed

+182
-138
lines changed

README.md

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
# Introduction to lists
33

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.
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. Now in this lesson, we'll see how we can group data together with lists.
55

66
### Creating a list
77

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.
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 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.
99

1010
#### Travel Locations
1111
1. Solta
@@ -21,7 +21,7 @@ A list is our first form of a collection. A collection is just a way of groupin
2121
11. Toronto
2222
12. Pyeongchang
2323

24-
And here is how that same list looks in Python:
24+
Here is what that list looks like as a Python `list`:
2525

2626

2727
```python
@@ -46,7 +46,7 @@ And here is how that same list looks in Python:
4646

4747

4848

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.
49+
We indicate that we are initializing a `list` with an opening bracket, `[`, and we end the list with a closing bracket `]`. We separate each list item, also called an element, with a comma.
5050

5151

5252
```python
@@ -71,7 +71,7 @@ So we indicate that we are initializing a `list` by placing a bracket, `[`, and
7171

7272

7373

74-
And of course, we can set each list equal to variable so that we can name each list.
74+
We can, of course, declare variables and set them equal to our lists so that we can both name and later retrieve the list.
7575

7676

7777
```python
@@ -108,13 +108,13 @@ countries_of_top_cities = ['Croatia', 'USA', 'Argentina', 'Mexico', 'USA', 'Moro
108108

109109
### Accessing Elements of Lists
110110

111-
Now our `top_travel_cities` list 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 are used to list elements having a rank or number associated with them...
112112

113113
1. Solta
114114
2. Greenville
115115
3. Buenos Aires
116116

117-
A list in Python also assigns a number to each element.
117+
...a list in Python also assigns a number to each element.
118118

119119

120120
```python
@@ -151,9 +151,9 @@ top_travel_cities[0]
151151

152152

153153

154-
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.
154+
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.
155155

156-
So to access the second element we write `top_travel_cities[1]`, and the third element is `top_travel_cities[2]`:
156+
So to access the second element we write `top_travel_cities[1]`, and the third element is `top_travel_cities[2]`.
157157

158158

159159
```python
@@ -167,7 +167,7 @@ top_travel_cities[2]
167167

168168

169169

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 end and move back one:
171171

172172

173173
```python
@@ -195,7 +195,7 @@ top_travel_cities[-2]
195195

196196

197197

198-
Each element in our list is a string, so we can always set an element of our string equal to a variable.
198+
Each element in our list is a string, so, we can always set an element of our string equal to a variable.
199199

200200

201201
```python
@@ -222,7 +222,7 @@ type(top_canadian_city)
222222

223223

224224

225-
So now we have a variable of `top_canadian_city`, equal to the string 'toronto', and a variable of `top_travel_cities` equal to the list of cities.
225+
Now we have a variable of `top_canadian_city`, equal to the string 'Toronto', and a variable of `top_travel_cities` equal to the list of cities.
226226

227227

228228
```python
@@ -261,7 +261,7 @@ type(top_travel_cities)
261261

262262
### Accessing Multiple Elements
263263

264-
Now imagine that we don't want to access just one element of a list, but multiple elements at once. Python allows us to do that as well.
264+
Now imagine that we don't want to access just one element of a list, but multiple elements at once. Python allows us to do that as well:
265265

266266

267267
```python
@@ -275,7 +275,7 @@ top_travel_cities[0:2]
275275

276276

277277

278-
Ok, now to access elements of a list, inside of our brackets we are placing two numbers separated by a colon. The first number indicates the index of the first element we want returned.
278+
As we can see from the above example, we can access elements of a list by placing two numbers separated by a colon inside of our brackets. The first number indicates the index of the first element we want returned.
279279

280280
The second number could represent the number of elements we want returned back, or maybe it represents the stopping index of the elements that we are retrieving. Looking at our `top_travel_cities` it could be either.
281281

@@ -302,7 +302,7 @@ top_travel_cities
302302

303303

304304

305-
So let's try a different experiment to answer our question.
305+
Let's try a different experiment to answer our question.
306306

307307

308308
```python
@@ -316,7 +316,7 @@ top_travel_cities[4:5]
316316

317317

318318

319-
Ok, so that second number is not representing the number of elements we want returned. Instead it must be used to indicate the index of the first element not selected.
319+
Ok, so that second number is not representing the number of elements we want returned. Instead it must be the index at which we stop our selection of elements.
320320

321321

322322
```python
@@ -330,7 +330,7 @@ top_travel_cities[4:6]
330330

331331

332332

333-
This operation is called the `slice`. So we can say we are `slicing` the elements with indices 4 and 5 in the line above. Note that even though we are `slicing` elements, our list remains in tact.
333+
This operation is called `slice`. So, we can say we are `slicing` the elements with indices 4 and 5 in the line above. Note that even though we are `slicing` elements, our list remains intact.
334334

335335

336336
```python
@@ -370,11 +370,11 @@ top_two
370370

371371

372372

373-
So now we have another variable called `top_two` that points to an array which contains an array of elements equal to the first two elements of `top_travel_cities`.
373+
Now we have another variable called `top_two` that points to an array which contains an array of elements equal to the first two elements of `top_travel_cities`.
374374

375375
### Changing elements with destructive methods
376376

377-
Now that we read and select certain elements from lists, let's work on changing these lists. To add a new element to a list, we can use the `append` method.
377+
Now that we can read and select certain elements from lists, let's work on changing these lists. To add a new element to a list, we can use the `append` method.
378378

379379

380380
```python
@@ -407,15 +407,35 @@ top_travel_cities
407407

408408

409409

410-
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.
410+
You will see that 'San Antonio' has been added to the list. 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.
411411

412412

413413
```python
414414
top_travel_cities.append('San Antonio')
415415
top_travel_cities
416416
```
417417

418-
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.
418+
419+
420+
421+
['Solta',
422+
'Greenville',
423+
'Buenos Aires',
424+
'Los Cabos',
425+
'Walla Walla Valley',
426+
'Marakesh',
427+
'Albuquerque',
428+
'Archipelago Sea',
429+
'Iguazu Falls',
430+
'Salina Island',
431+
'Toronto',
432+
'Pyeongchang',
433+
'San Antonio',
434+
'San Antonio']
435+
436+
437+
438+
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.
419439

420440

421441
```python
@@ -429,7 +449,7 @@ top_travel_cities.pop()
429449

430450

431451

432-
Now if we want to change an element from the middle of the list, we can access and then reassign that element. So for example, let's change 'Walla Walla Valley' to the number 4.
452+
Now if we want to change an element from the middle of the list, we can access and then reassign that element. For example, let's change 'Walla Walla Valley' to the number 4.
433453

434454

435455
```python
@@ -472,14 +492,14 @@ top_travel_cities
472492

473493

474494

475-
And our list is now changed. It's not a sensible list right now, so let's change it back.
495+
Our list is changed, but now it's not as sensible, so let's change it back.
476496

477497

478498
```python
479499
top_travel_cities[4] = 'Walla Walla Valley'
480500
```
481501

482-
And our list is alright.
502+
With that, our list is back to the way we like it.
483503

484504

485505
```python
@@ -507,7 +527,7 @@ top_travel_cities
507527

508528
### Finding Unique elements and length of lists
509529

510-
If we are not sure if there are repeated elements, we can use Python to get a unique list.
530+
If we are not sure whether there are repeated elements, we can use Python to get a unique list.
511531

512532

513533
```python
@@ -547,13 +567,13 @@ The set function initializes a new set in Python. A set is a different type col
547567

548568

549569
```python
550-
set()
570+
type(set())
551571
```
552572

553573

554574

555575

556-
set()
576+
set
557577

558578

559579

@@ -565,11 +585,11 @@ unique_travel_cities[1]
565585
```
566586

567587

568-
---------------------------------------------------------------------------
588+
-------------------------------------------------------------------
569589

570-
TypeError Traceback (most recent call last)
590+
TypeError Traceback (most recent call last)
571591

572-
<ipython-input-106-8d1dfec3493a> in <module>()
592+
<ipython-input-26-3d2453cad46e> in <module>()
573593
----> 1 unique_travel_cities[1]
574594

575595

@@ -619,19 +639,19 @@ unique_travel_cities
619639

620640

621641

622-
['Archipelago Sea',
642+
['Toronto',
643+
'Archipelago Sea',
623644
'Iguazu Falls',
624-
'Solta',
645+
'Pyeongchang',
625646
'Los Cabos',
626-
'Walla Walla Valley',
627-
'Greenville',
628-
'Marakesh',
629-
'Toronto',
630-
'San Antonio',
631647
'Buenos Aires',
632-
'Salina Island',
648+
'Marakesh',
649+
'Greenville',
633650
'Albuquerque',
634-
'Pyeongchang']
651+
'Salina Island',
652+
'Walla Walla Valley',
653+
'San Antonio',
654+
'Solta']
635655

636656

637657

@@ -686,6 +706,8 @@ top_travel_cities
686706

687707

688708

709+
> **Note:** *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.*
710+
689711
### Summary
690712

691-
In this section we saw how to associate data together in a collection, called a list. A list is similar to a list in the real world - it implies the data has some connection, and that it has an order to it. We initialize a list with the brackets, `[]`, and separate each element by a comma. To access elements from a list, we use the bracket accessor followed by the index of the element we want to retrieve. And our indices began at zero and increase from there. To add a new element to the end of the list we use the `append` method, and to remove an element from the end of a list we use `pop`. We can change elements anywhere between by first accessing the elements and then reassigning them.
713+
In this section we saw how to associate data together in a collection, called a list. A list is similar to a list in the real world - it implies the data has some connection, and that it has an order to it. We initialize a list with the brackets, `[]`, and separate each element by a comma. To access elements from a list, we use the bracket accessor followed by the index of the element we want to retrieve, and our indices begin at zero and increase from there. To add a new element to the end of the list we use the `append` method, and to remove an element from the end of a list we use `pop`. We can change elements anywhere between by first accessing the elements and then reassigning them.

0 commit comments

Comments
 (0)