1
00:00:00,610 --> 00:00:03,070
Hello, my name is Stefan from Oxford Academy.

2
00:00:03,070 --> 00:00:06,160
And in this section you will learn about lists.

3
00:00:06,190 --> 00:00:11,030
What lists are and how to start working with the elements in a list.

4
00:00:11,050 --> 00:00:18,190
So let's allow you to store sets of information in one place, whether you have just a few items or

5
00:00:18,190 --> 00:00:19,600
millions of items.

6
00:00:19,600 --> 00:00:29,860
So lists are one of the python's most powerful features, readily accessible to new programmers, and

7
00:00:29,860 --> 00:00:33,700
they tie together many important concepts in programming.

8
00:00:33,700 --> 00:00:36,520
So what is a list?

9
00:00:36,700 --> 00:00:38,560
A list is a collection of items.

10
00:00:38,560 --> 00:00:39,880
In a particular order.

11
00:00:39,910 --> 00:00:46,390
You can make a list that includes the letter alphabets.

12
00:00:47,260 --> 00:00:48,600
Digits here.

13
00:00:48,730 --> 00:00:49,780
Letters.

14
00:00:50,690 --> 00:00:53,000
A, B or.

15
00:00:54,410 --> 00:00:57,770
A the C here ads here.

16
00:00:57,800 --> 00:01:01,840
You can create a list of numbers here.

17
00:01:01,850 --> 00:01:03,920
One two.

18
00:01:05,760 --> 00:01:08,100
Three, four.

19
00:01:08,840 --> 00:01:09,590
Five.

20
00:01:09,800 --> 00:01:11,300
You can also create.

21
00:01:14,350 --> 00:01:16,810
List of characters here.

22
00:01:19,690 --> 00:01:28,270
Which you will learn all of this in this section so you can put anything you want into list and the

23
00:01:28,270 --> 00:01:32,130
items in your list don't have to be related in a particular way, right?

24
00:01:32,140 --> 00:01:42,010
So because a list is usually contains more than one element, it's a good idea to make the name of your

25
00:01:42,010 --> 00:01:43,330
list plural.

26
00:01:43,330 --> 00:01:44,740
Such as?

27
00:01:45,250 --> 00:01:48,310
Uh, for example, instead of writing.

28
00:01:48,340 --> 00:01:49,120
Oh, sorry.

29
00:01:49,820 --> 00:01:54,530
So instead of writing your list variable name letter.

30
00:01:58,550 --> 00:02:06,320
You can write letters because it's a more good practice here.

31
00:02:06,320 --> 00:02:08,180
So in Python.

32
00:02:08,390 --> 00:02:10,100
Square braces.

33
00:02:10,100 --> 00:02:12,410
This square braces.

34
00:02:15,850 --> 00:02:23,080
Indicator list and individual elements in the list are separated by commas.

35
00:02:25,620 --> 00:02:28,640
Separated by commas.

36
00:02:28,680 --> 00:02:30,930
So let's actually create a.

37
00:02:31,970 --> 00:02:35,880
Example, a list that contains a few kinds of courses.

38
00:02:35,920 --> 00:02:36,500
Right?

39
00:02:36,500 --> 00:02:37,580
So.

40
00:02:38,840 --> 00:02:42,050
So course topics here.

41
00:02:42,080 --> 00:02:44,330
It's going to be here.

42
00:02:44,330 --> 00:02:47,450
We have braces, brackets.

43
00:02:47,450 --> 00:02:50,450
So now we're going to car.

44
00:02:50,480 --> 00:02:55,670
As you can see, we are getting an error because we we need to enter a strings car.

45
00:02:56,030 --> 00:02:57,200
So we use single quotes.

46
00:02:59,410 --> 00:03:00,190
Car.

47
00:03:00,520 --> 00:03:05,080
And here we will also add Android Kotlin.

48
00:03:05,410 --> 00:03:08,260
We will also add Java.

49
00:03:09,830 --> 00:03:10,670
Python.

50
00:03:14,040 --> 00:03:15,900
Digital forensics.

51
00:03:16,720 --> 00:03:20,230
Actually, let's decrease the font size a little bit maybe.

52
00:03:20,230 --> 00:03:20,740
Yeah.

53
00:03:20,770 --> 00:03:22,690
And digital fonts is okay for now.

54
00:03:22,720 --> 00:03:28,000
So after that we will print the course topics list.

55
00:03:28,390 --> 00:03:32,470
And as you can see here, this is the output.

56
00:03:32,650 --> 00:03:40,990
So if you ask a python, print the list that's Python retains its representation of a list, including

57
00:03:40,990 --> 00:03:42,910
the square braces here.

58
00:03:42,940 --> 00:03:48,670
So because this is the output you want to use, you want users to see.

59
00:03:48,700 --> 00:03:52,960
Let's learn how to access the individual items.

60
00:03:53,380 --> 00:04:01,660
For example, Car, Android, Kotlin, Java, Python and digital forensics.

61
00:04:01,900 --> 00:04:03,130
Let's try this now.

62
00:04:03,130 --> 00:04:12,400
So lists are ordered collections so you can access any element in a list by telling Python the position

63
00:04:12,400 --> 00:04:15,130
or index of the item desired.

64
00:04:15,160 --> 00:04:23,060
So to access an element in a list, write the name of the list followed by the end index of the item.

65
00:04:23,060 --> 00:04:25,520
So now there's an interesting thing I want to.

66
00:04:26,540 --> 00:04:26,890
Sorry.

67
00:04:27,350 --> 00:04:28,610
Firstly, it's actually get.

68
00:04:29,520 --> 00:04:36,110
And so in order to access this list, we will write, print or actually instead of print, we can also

69
00:04:36,110 --> 00:04:36,500
write.

70
00:04:36,530 --> 00:04:40,460
Yeah, we will write print inside this list.

71
00:04:40,460 --> 00:04:42,920
We will get course topics here.

72
00:04:43,580 --> 00:04:44,630
Course.

73
00:04:50,020 --> 00:04:50,860
Topics.

74
00:04:52,550 --> 00:04:54,350
And here we will use.

75
00:04:55,710 --> 00:04:56,420
Braces.

76
00:04:56,460 --> 00:04:58,260
Brackets like this.

77
00:04:58,380 --> 00:05:01,440
Let's actually use this different color so I can show you.

78
00:05:02,220 --> 00:05:02,620
Here.

79
00:05:04,220 --> 00:05:07,240
This is the braces.

80
00:05:07,250 --> 00:05:11,840
So here we will add the nth element.

81
00:05:11,840 --> 00:05:12,680
So.

82
00:05:14,080 --> 00:05:14,650
And.

83
00:05:16,310 --> 00:05:17,030
Element.

84
00:05:21,010 --> 00:05:21,870
From list.

85
00:05:28,450 --> 00:05:29,860
So in this case.

86
00:05:30,500 --> 00:05:34,550
For example, if we want to access the cars, the car is going to be zero.

87
00:05:34,910 --> 00:05:40,030
Android Kotlin is going to be remember, let's let's actually use different color.

88
00:05:40,130 --> 00:05:41,060
So.

89
00:05:41,970 --> 00:05:43,950
The car is going to be.

90
00:05:46,810 --> 00:05:47,680
Zero.

91
00:05:47,710 --> 00:05:52,110
Android Kotlin is going to be one.

92
00:05:52,120 --> 00:05:55,180
Java is going to be two.

93
00:05:55,450 --> 00:05:58,720
Python is going to be third element in the list.

94
00:06:00,490 --> 00:06:04,500
Digital forensics is going to be fourth element in the list.

95
00:06:04,510 --> 00:06:07,840
So if you want to access the cars, we will write zero.

96
00:06:07,840 --> 00:06:12,130
If you want to access the Android Kotlin, we will write one here.

97
00:06:12,340 --> 00:06:16,240
But if we want to access Java, we will write two.

98
00:06:16,270 --> 00:06:23,770
If we want to access Python, as you know, we will write three because the python is the third element

99
00:06:23,770 --> 00:06:24,490
of the list.

100
00:06:24,490 --> 00:06:28,990
So list starts from the zero one, 234.

101
00:06:29,320 --> 00:06:34,360
So if we want to access the digital forensics, we will write the fourth.

102
00:06:35,360 --> 00:06:36,080
So.

103
00:06:39,150 --> 00:06:43,500
So here we will write course, print course topics.

104
00:06:44,960 --> 00:06:45,350
Zero.

105
00:06:45,350 --> 00:06:46,940
And as you can see, it's a car.

106
00:06:48,120 --> 00:06:48,570
Android.

107
00:06:48,570 --> 00:06:49,320
Kotlin.

108
00:06:50,610 --> 00:06:51,210
Java.

109
00:06:52,380 --> 00:06:53,070
Python.

110
00:06:54,930 --> 00:07:01,230
Now python and let's five ops and let's actually try Python now.

111
00:07:01,810 --> 00:07:02,290
So.

112
00:07:03,290 --> 00:07:05,390
I feel Bradford is going to be digital forensics.

113
00:07:05,390 --> 00:07:09,210
As we know, as I showed you earlier in this lecture.

114
00:07:09,230 --> 00:07:12,870
One, two, three, four, five.

115
00:07:12,890 --> 00:07:13,330
Right.

116
00:07:13,340 --> 00:07:16,030
Fifth element of the list in this case.

117
00:07:16,040 --> 00:07:20,330
Zero, one, two, three, four from the index.

118
00:07:20,630 --> 00:07:28,160
So here, if you write 5 or 10, in this case, we don't have that range or that index.

119
00:07:28,160 --> 00:07:32,810
And as you can see, list index out of range because we don't have that much item.

120
00:07:33,500 --> 00:07:38,810
So this is the result you want to users to see in this case, for example, Java, right.

121
00:07:39,260 --> 00:07:41,720
So nearly formatted output.

122
00:07:41,720 --> 00:07:48,060
So you can also use the string methods from previous lectures on any element.

123
00:07:48,070 --> 00:07:53,330
This list, for example, course topics that we will write here.

124
00:07:53,450 --> 00:08:01,210
So we have l strip lower upper let's upper and here, as you can see, we have uppercase Java.

125
00:08:01,220 --> 00:08:06,050
So Python here considers the first item.

126
00:08:06,050 --> 00:08:12,560
Actually, let me let me I want to explain this later because most new programmers.

127
00:08:13,390 --> 00:08:16,660
Have problem with this index thing here.

128
00:08:16,660 --> 00:08:25,270
So Python considers the first item in a list to be at a position zero.

129
00:08:25,270 --> 00:08:28,180
In the end, most programming language is actually considered like this.

130
00:08:28,180 --> 00:08:33,520
So here the car is worth zero, right?

131
00:08:33,910 --> 00:08:34,780
Zero.

132
00:08:37,490 --> 00:08:41,420
And this is not the first car is a zero at the index.

133
00:08:41,420 --> 00:08:44,330
This is true of most programming languages.

134
00:08:44,330 --> 00:08:51,070
And the reason has to do with how the list operations are implemented at a lower level.

135
00:08:51,080 --> 00:08:54,740
So if you are receiving an unexpected results.

136
00:08:56,150 --> 00:09:01,640
Ask yourself if you are making a simple but common off by one error.

137
00:09:01,730 --> 00:09:07,190
So the second item in the list has an index of.

138
00:09:07,880 --> 00:09:09,530
One of.

139
00:09:11,540 --> 00:09:16,310
The second item in the list has an index of one.

140
00:09:19,740 --> 00:09:20,220
Here.

141
00:09:20,610 --> 00:09:22,190
So let's make this.

142
00:09:23,580 --> 00:09:25,380
And the third item.

143
00:09:26,940 --> 00:09:30,630
As an index of two again.

144
00:09:34,740 --> 00:09:35,970
The fourth item.

145
00:09:37,290 --> 00:09:38,430
As the index.

146
00:09:39,370 --> 00:09:40,840
Of three.

147
00:09:42,430 --> 00:09:47,200
And the fifth item has an index of four.

148
00:09:49,070 --> 00:09:49,770
That's it.

149
00:09:49,790 --> 00:09:53,360
So this code here.

150
00:09:54,480 --> 00:09:55,260
For example.

151
00:09:55,260 --> 00:09:56,130
Now let's.

152
00:09:57,890 --> 00:09:58,430
Here.

153
00:09:58,700 --> 00:09:59,630
So.

154
00:10:03,030 --> 00:10:05,850
Now we will print here.

155
00:10:07,340 --> 00:10:08,300
Zero.

156
00:10:12,280 --> 00:10:15,010
Let's actually copy this again and again.

157
00:10:18,800 --> 00:10:19,020
Four.

158
00:10:19,070 --> 00:10:19,550
Five.

159
00:10:20,400 --> 00:10:20,850
So.

160
00:10:21,120 --> 00:10:25,260
Zero one, two, three, four.

161
00:10:26,750 --> 00:10:29,930
And here, as you can see here, this is our output, right?

162
00:10:29,960 --> 00:10:37,160
The 012 here, zero goes to here.

163
00:10:38,180 --> 00:10:44,090
The one goes to here, the three goes to here, the second line index.

164
00:10:44,090 --> 00:10:47,300
Of course, the fourth index goes to here.

165
00:10:47,300 --> 00:10:52,910
And digital forensics, the last index fourth goes to here.

166
00:10:53,090 --> 00:11:03,230
So the python has a special syntax for accessing the last element in a list if you ask for them at indexed

167
00:11:03,260 --> 00:11:07,310
index Z minus negative one here.

168
00:11:07,310 --> 00:11:08,810
Let's let's try this.

169
00:11:10,340 --> 00:11:11,420
This is the weird, right?

170
00:11:11,690 --> 00:11:15,170
And as you can see here, negative one.

171
00:11:16,610 --> 00:11:26,120
If you ask for the item at the index negative one python will always returns the last item.

172
00:11:26,120 --> 00:11:31,280
Negative one returns negative one.

173
00:11:32,610 --> 00:11:33,870
Returns.

174
00:11:37,660 --> 00:11:38,860
Returns.

175
00:11:42,040 --> 00:11:44,020
Returns the last item.

176
00:11:53,040 --> 00:11:53,280
Yeah.

177
00:11:53,760 --> 00:12:02,940
So here the the code returns the digital forensics and this syntax is quite useful because you will

178
00:12:02,940 --> 00:12:07,950
often want to access the last items in a list without knowing exactly how long the list is.

179
00:12:07,950 --> 00:12:17,100
So the convention extend other negative index values as well, and the index minus two returns the second

180
00:12:17,100 --> 00:12:19,140
item from the end of the list.

181
00:12:19,620 --> 00:12:20,250
Yeah.

182
00:12:21,090 --> 00:12:28,260
And the index minus three returns the third item from the end and so forth.
