Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,140 --> 00:00:00,470
OK.
2
00:00:00,480 --> 00:00:02,540
Now let's talk about lists.
3
00:00:02,670 --> 00:00:05,250
So lists are data structures.
4
00:00:05,250 --> 00:00:09,720
Now these data structures are changeable that we can re order them.
5
00:00:09,720 --> 00:00:11,970
Put them in a list.
6
00:00:11,970 --> 00:00:12,270
Right.
7
00:00:12,270 --> 00:00:14,180
So they're just a group of elements.
8
00:00:14,220 --> 00:00:19,830
And when you when you have this list everything inside that list is called an item.
9
00:00:19,830 --> 00:00:24,330
And the best way to think of a list is to think that it lives in between brackets.
10
00:00:24,330 --> 00:00:30,510
You're going to see other things later on that look like a list but it's not really a list because of
11
00:00:30,810 --> 00:00:36,900
how it's defined and how we're going to define lists is because they live in brackets just like a string
12
00:00:36,900 --> 00:00:38,430
might have quotes around it.
13
00:00:38,430 --> 00:00:40,430
A list is going to have these brackets around it.
14
00:00:40,500 --> 00:00:48,390
So let's make a new line and let's go ahead and just do something along the lines of lists and we could
15
00:00:48,430 --> 00:00:53,490
say something like have the brackets like this.
16
00:00:54,630 --> 00:00:55,410
OK.
17
00:00:55,650 --> 00:00:59,680
So let's go ahead and make a list and then we can kind of go from there.
18
00:00:59,700 --> 00:01:03,090
So let's define a list of your favorite movies.
19
00:01:03,090 --> 00:01:08,820
Now you can put in whatever favorite movies you like in here and I'm going to put in something like
20
00:01:10,200 --> 00:01:11,550
When Harry Met Sally
21
00:01:15,470 --> 00:01:16,580
the hangover
22
00:01:19,850 --> 00:01:28,100
The Perks of Being A Wallflower and this is getting kind of long so I'm actually going to move this
23
00:01:28,100 --> 00:01:33,490
over a little bit for us and we'll say one more let's pick for movies.
24
00:01:33,500 --> 00:01:35,080
We'll do the exorcist.
25
00:01:35,740 --> 00:01:36,160
OK.
26
00:01:37,040 --> 00:01:40,660
And now we have this this list again list.
27
00:01:40,670 --> 00:01:41,930
Just live in brackets.
28
00:01:41,940 --> 00:01:48,340
So we've got list item one item two item three and item for OK.
29
00:01:48,390 --> 00:01:50,580
So let's go ahead and print these.
30
00:01:50,580 --> 00:01:59,070
So if we were to print out something like movies and we said we wanted to print the first item out of
31
00:01:59,070 --> 00:02:01,560
movies let's go ahead and try to print When Harry Met Sally.
32
00:02:01,590 --> 00:02:07,560
So print the first item so put a bracket around it just like this or print it out and we'll see what
33
00:02:07,560 --> 00:02:08,610
happens.
34
00:02:08,640 --> 00:02:09,520
So let's say that.
35
00:02:09,870 --> 00:02:15,780
And what's it going to return for us it's returning the hangover.
36
00:02:15,780 --> 00:02:20,190
So item one is not item one as you see it.
37
00:02:20,580 --> 00:02:28,660
So when we talk about items and we talk about numerical order here in Python item one is actually going
38
00:02:28,660 --> 00:02:31,050
to be referred to as zero.
39
00:02:31,060 --> 00:02:35,540
So make a note here for yourself that this will return.
40
00:02:35,590 --> 00:02:37,890
The second item.
41
00:02:38,290 --> 00:02:45,820
So if we wanted to return just When Harry Met Sally we would actually put in movies Zero like this and
42
00:02:45,820 --> 00:02:51,340
we could say returns the first item in the list.
43
00:02:51,950 --> 00:02:52,500
OK.
44
00:02:52,570 --> 00:02:57,000
And we can say that and let's go ahead and give it a go.
45
00:02:57,000 --> 00:02:58,500
Just to do proof of concept.
46
00:02:58,500 --> 00:02:59,670
And there you go.
47
00:02:59,670 --> 00:03:03,330
Remember that everything starts with zero and not one.
48
00:03:03,330 --> 00:03:07,820
So when you're thinking about things let's think about them with zero as the beginning.
49
00:03:07,830 --> 00:03:09,550
No.
50
00:03:09,720 --> 00:03:13,020
So let's go ahead and do a few more different prints.
51
00:03:13,020 --> 00:03:15,840
What's gonna happen when we print out something like this.
52
00:03:15,840 --> 00:03:21,270
We'll say movies and we'll do one through three.
53
00:03:21,450 --> 00:03:22,450
You have a hunch.
54
00:03:22,500 --> 00:03:24,090
Let's go ahead and save it.
55
00:03:25,670 --> 00:03:35,730
Print it out here and it will take the list here of starting at 1 and it'll end before 3.
56
00:03:35,770 --> 00:03:40,090
So let's say we want to pull a couple of items out the first number that we're going to pull out is
57
00:03:40,090 --> 00:03:42,430
going to be the one that we want to start with.
58
00:03:42,490 --> 00:03:47,620
And the last number that we're going to pull out is going to be the number where we're going to stop.
59
00:03:47,650 --> 00:03:49,770
So the X axis is three.
60
00:03:49,800 --> 00:03:55,330
But if we wanted to actually pull down the axis we would have to pull down four here.
61
00:03:55,330 --> 00:03:59,260
So if we want to try to grab more than one thing on the list we can absolutely do that.
62
00:03:59,380 --> 00:04:01,030
But we have to know where to stop.
63
00:04:01,030 --> 00:04:04,150
So now we incorporate the exorcist here.
64
00:04:04,210 --> 00:04:10,420
Let's say we want to grab everything in a list and we wanted to grab everything after a certain point.
65
00:04:10,420 --> 00:04:10,720
Right.
66
00:04:10,720 --> 00:04:18,760
We could say something like movies one like this and then we should be able to grab every single thing
67
00:04:20,710 --> 00:04:23,610
and that does pretty much the same thing here.
68
00:04:23,610 --> 00:04:30,630
So if we had 30 items here it would grab all 30 items in this list if we wanted to grab three items
69
00:04:30,690 --> 00:04:32,970
as we did before we would do one.
70
00:04:33,180 --> 00:04:35,720
And then you just add three to that to four.
71
00:04:35,730 --> 00:04:37,050
And it would stop.
72
00:04:37,050 --> 00:04:38,460
So a little bit confusing.
73
00:04:38,490 --> 00:04:40,800
This takes a little bit to wrap your mind around.
74
00:04:41,340 --> 00:04:47,010
But the good thing here is that you take notes you can make notes however you feel comfortable with.
75
00:04:47,400 --> 00:04:50,200
And these tricks should be useful for you.
76
00:04:50,220 --> 00:04:52,530
So let's try another thing.
77
00:04:52,530 --> 00:04:57,060
What if we said something like movies and we did this one in reverse.
78
00:04:57,090 --> 00:05:02,390
We just did something like this when we did save Let's print it out.
79
00:05:02,400 --> 00:05:08,050
What do you think's going to have an it's going to print When Harry Met Sally because it's going to
80
00:05:08,050 --> 00:05:14,950
stop at the one we never get to one here again similar situation when we had this set of three we never
81
00:05:14,950 --> 00:05:16,500
get to one we stop at one.
82
00:05:16,540 --> 00:05:22,210
So we're gonna grab everything before one which is going to be just be When Harry Met Sally we could
83
00:05:22,210 --> 00:05:25,430
set this to two and we would grab the hangover in this as well.
84
00:05:25,600 --> 00:05:27,180
And just to prove concept here.
85
00:05:27,600 --> 00:05:29,470
So that I'm not crazy.
86
00:05:29,470 --> 00:05:34,120
You can see here the hangover gets added in because we get zero and we grab one.
87
00:05:34,180 --> 00:05:41,590
You could also think of this if you don't confuse herself as grabbing two items out of the list but
88
00:05:41,590 --> 00:05:46,600
make sure you don't confuse yourself because if this number were to be like two through four then it
89
00:05:46,600 --> 00:05:48,190
would be something completely different.
90
00:05:48,190 --> 00:05:48,920
Right.
91
00:05:48,970 --> 00:05:53,120
So you need to make sure that you understand where from the list that you're actually grabbing where
92
00:05:53,210 --> 00:05:55,290
Senate controls ease back.
93
00:05:56,190 --> 00:06:02,590
So from here let's do two more tricks.
94
00:06:02,590 --> 00:06:06,780
Actually we'll do one more trick and they'll move into some other items related to lists.
95
00:06:06,790 --> 00:06:15,460
So if we say movies like this and we want to grab the very last item we can just put in a negative one
96
00:06:16,300 --> 00:06:19,320
and so grab the absolute last item off the list.
97
00:06:19,450 --> 00:06:20,030
That way.
98
00:06:20,140 --> 00:06:24,480
If you have a list that's two thousand items long and you don't know where it ends.
99
00:06:24,490 --> 00:06:25,630
You could just do negative one.
100
00:06:25,630 --> 00:06:31,180
It's going to grab the last item for you and then you can see there it grab down the exorcist.
101
00:06:31,360 --> 00:06:37,870
So cool little tricks you might not use these for a while and you probably won't see these come through
102
00:06:37,870 --> 00:06:41,950
at least in anything we're going to really do in the course but they're still incredibly useful to know
103
00:06:41,950 --> 00:06:45,540
about because they're they are included in the basics of Python.
104
00:06:45,550 --> 00:06:52,060
So you're going to know the basics of Python and you will use these sometime in your lifetime.
105
00:06:52,060 --> 00:06:57,670
It's useful to know this kind of stuff so we can also do some things with list as well.
106
00:06:58,060 --> 00:07:06,850
We can print out the length of our lists so we can say length of movies something like this and get
107
00:07:06,850 --> 00:07:10,300
that ago and you can see that there's four items in that list.
108
00:07:10,990 --> 00:07:16,010
So we've seen length before with strings and it took every single character inside that string.
109
00:07:16,060 --> 00:07:21,180
Here it's taking every single amount of item inside a list and pointing that out.
110
00:07:21,250 --> 00:07:27,300
We can also append items to the list so we can say something like movies dot a pen.
111
00:07:27,310 --> 00:07:31,320
And what if we really like Jaws and we add that into our favorite movies.
112
00:07:31,450 --> 00:07:33,220
You can have too many favorite movies come on.
113
00:07:33,280 --> 00:07:40,630
So let's go ahead and try printing that out and while we have to actually print it sorry movies out
114
00:07:40,630 --> 00:07:47,860
of hand and then we say print movies now and it should print out with jobs added in.
115
00:07:47,860 --> 00:07:53,370
Where do we think jobs is going to actually add itself into well if you said the end of the list you
116
00:07:53,370 --> 00:07:54,790
are correct.
117
00:07:54,790 --> 00:08:00,600
So when we append something we append it to the very end of the list.
118
00:08:00,730 --> 00:08:06,880
What if we wanted to delete something from the list we could say something like this movie stop pop
119
00:08:08,440 --> 00:08:11,110
and print movies.
120
00:08:11,200 --> 00:08:12,360
Let's see what happens here
121
00:08:18,390 --> 00:08:20,110
and now we got rid of Jaws.
122
00:08:20,130 --> 00:08:25,470
So when we append We append to the end of the list if we want to delete the very last item in the list
123
00:08:25,860 --> 00:08:27,630
we just use pop.
124
00:08:27,690 --> 00:08:35,280
Now if we wanted to delete something like the first item or the second item we could do movies that
125
00:08:35,280 --> 00:08:40,010
top and let's say 0 print movies.
126
00:08:40,840 --> 00:08:46,010
So remove the very very first item in the list we should see you inherently disappear.
127
00:08:46,380 --> 00:08:47,100
And there you go.
128
00:08:47,100 --> 00:08:50,500
No longer is When Harry Met Sally and our list.
129
00:08:50,520 --> 00:08:53,810
So this is a quick way that we can remove these items.
130
00:08:54,060 --> 00:08:58,340
And on the fly if we need to to get rid of this.
131
00:08:58,440 --> 00:09:04,830
So the high level overview here and the thing that you really need to take away is that list have brackets.
132
00:09:04,830 --> 00:09:07,220
We're going to see something called dictionaries later.
133
00:09:07,230 --> 00:09:14,250
We might see something called tuples later and they all look very very similar but here lists have brackets
134
00:09:14,580 --> 00:09:19,170
inside those brackets are what we have that are called items.
135
00:09:19,270 --> 00:09:19,650
OK.
136
00:09:19,650 --> 00:09:22,590
And there are many different ways to return items.
137
00:09:22,650 --> 00:09:27,900
The reason that I'm showing you these different ways is so that you can get familiar with the syntax
138
00:09:28,350 --> 00:09:36,690
that we start our list or our items with zero and not one and that we can grab from these lists in different
139
00:09:36,690 --> 00:09:37,840
ways.
140
00:09:37,860 --> 00:09:38,310
OK.
141
00:09:38,310 --> 00:09:43,890
And this will come back into play later with how we can utilize this same kind of syntax with other
142
00:09:43,890 --> 00:09:50,730
items as well or other things in Python so we can also utilize you know printing out length or we can
143
00:09:50,730 --> 00:09:57,810
do a append and add to the list or dot pop and there's a lot of different things that we can do here
144
00:09:58,260 --> 00:10:02,280
to you know to append to these lists or remove from these lists et cetera.
145
00:10:02,310 --> 00:10:08,250
So this is just the basics but hopefully what you take away from this is that lists have brackets and
146
00:10:08,600 --> 00:10:13,300
you know the items there are items in the list and they start with zero.
147
00:10:13,320 --> 00:10:14,760
Those are the key takeaways.
148
00:10:14,760 --> 00:10:21,300
So in the next video we're going to briefly talk about tuples and then we're gonna move on into looping.
149
00:10:21,300 --> 00:10:22,620
So let's go ahead and do that.
14596
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.