1
00:00:04,689 --> 00:00:08,799
So let's have another look now, at the
immutable sequences type section of the

2
00:00:08,799 --> 00:00:14,860
documentation, and paste the link into
Google. Now this table shows all the

3
00:00:14,860 --> 00:00:19,610
operations that are supported for mutable sequences.

4
00:00:19,610 --> 00:00:24,230
The only mutable sequence type that's
built into Python is the list, but there

5
00:00:24,230 --> 00:00:28,430
are other types in the standard library.
Now note that this table is only showing

6
00:00:28,430 --> 00:00:32,418
operations for mutable sequences. If we
scroll up and look at early in this

7
00:00:32,418 --> 00:00:38,840
document, here under common sequence
operations, you can see the operations

8
00:00:38,840 --> 00:00:44,060
that apply to all sequences - so that
includes strings and tuples, as well as lists.

9
00:00:44,060 --> 00:00:47,440
Now we've seen some of these
operations in the last section, and again

10
00:00:47,449 --> 00:00:53,299
they apply to both mutable and immutable
sequence types. I didn't cover index and

11
00:00:53,299 --> 00:00:57,110
count but we'll be looking at them,
shortly, and I also didn't cover min and

12
00:00:57,110 --> 00:01:01,159
max, but it's fairly obvious what they do.
So let's see some examples, so we'll

13
00:01:01,160 --> 00:01:08,480
switch back to the code. I'm gonna start
by creating a new Python file called number_lists.

14
00:01:15,000 --> 00:01:20,160
Let's start by typing even equals, left square bracket

15
00:01:20,160 --> 00:01:27,020
2, 4, 6, 8 and right square bracket to close
it off. The next line, odd equals left square

16
00:01:27,020 --> 00:01:35,210
bracket 1, 3, 5, 7, 9 right square bracket. So we've got two

17
00:01:35,210 --> 00:01:40,850
lists here: even contains even numbers,
and odd contains odd numbers. If we use

18
00:01:40,850 --> 00:01:45,080
min and max, we should get 2 and 8
for even and 1 and 9 for odd, so let's

19
00:01:45,080 --> 00:01:52,040
try that. So print left parenthesis min
left parenthesis even, and the two closing

20
00:01:52,040 --> 00:01:55,610
right parentheses. We'll do the same
but for max, so print left parenthesis,

21
00:01:55,610 --> 00:02:00,980
max left parenthesis even and the two
right parentheses. We'll do the same for

22
00:02:00,980 --> 00:02:09,060
our odd as well, so print min odd - the
same for max as well, for odd.

23
00:02:09,060 --> 00:02:19,159
Alright, so let's run the program now. No surprises there - 2 and 8 and 1 and 9 is the output. So moving on,

24
00:02:19,159 --> 00:02:23,690
len returns the number of items in the
sequence. For a string, that would be the

25
00:02:23,690 --> 00:02:27,400
number of characters in the string. For a
list though, it's the number of items.

26
00:02:27,400 --> 00:02:30,240
So let's try that out.

27
00:02:30,790 --> 00:02:35,380
Line nine, print left and right
parentheses - add an extra line break

28
00:02:35,380 --> 00:02:39,840
there, an extra line to separate the
output. Line ten, print left parenthesis

29
00:02:39,840 --> 00:02:45,880
len left parenthesis even. Then line 11,
we'll do the same for odd, so print, left

30
00:02:45,880 --> 00:02:53,650
parenthesis len left parenthesis odd,
like so. Let's run this, and you see we

31
00:02:53,650 --> 00:02:56,709
get 4 for the length of even. That's
because it contains four numbers,

32
00:02:56,709 --> 00:03:02,050
and 5 for odd - no surprises because it
contains five numbers. Now our list's aren't very

33
00:03:02,050 --> 00:03:06,880
good at seeing what count does, because
each number only appears once in the lists.

34
00:03:06,880 --> 00:03:09,940
We can use a string, instead, to
demonstrate this, so let's see how many

35
00:03:09,940 --> 00:03:17,380
times the letter s appears in
Mississippi. So adding a line there, line

36
00:03:17,380 --> 00:03:21,519
break between our content, our output, and line 13, I'm going to type print left

37
00:03:21,519 --> 00:03:24,220
parenthesis, double quotes Mississippi - if I could

38
00:03:24,220 --> 00:03:31,800
spell it right - mi ss iss i ppi
closing double quote then dot count,

39
00:03:31,800 --> 00:03:38,560
parentheses double quotes and s in the
double quotes, close off the line.

40
00:03:38,560 --> 00:03:44,880
Let's run this now, and you can see we've got
the answer 4 there. I used a single

41
00:03:44,890 --> 00:03:49,359
character here - the letter s, as you can
see - but we could use longer strings

42
00:03:49,359 --> 00:03:57,400
and get the count of that. So let's change
the s to iss. Let's run that. This time

43
00:03:57,400 --> 00:04:03,250
we've got the result 2. The string iss
appears twice in Mississippi. Now, note

44
00:04:03,250 --> 00:04:07,420
that a character will only be used once
when counting. You may look at the string

45
00:04:07,420 --> 00:04:12,940
and think that issi appears twice, but
that would involve re-using the middle

46
00:04:12,940 --> 00:04:18,339
letter i. So as we can see, when I change
this program to search for issi, or to

47
00:04:18,339 --> 00:04:26,380
count rather, issi - run that. You can see
we get the answer 1 and not 2. We saw

48
00:04:26,380 --> 00:04:30,039
the index method in the last section,
when we searched the shopping list. At the

49
00:04:30,039 --> 00:04:33,160
time I said that the code could be made
more efficient, so I'm going to come back

50
00:04:33,160 --> 00:04:37,240
to index soon, in this section. Before
that though, in the next video, we'll look

51
00:04:37,240 --> 00:04:40,690
at the table that I started the video
with - the operations we can perform with

52
00:04:40,690 --> 00:04:45,360
mutable sequence types. See you in the
next video.

