1
00:00:06,560 --> 00:00:11,790
So, let's go over some of the things that we've learned so far.

2
00:00:11,790 --> 00:00:17,490
So, remember that slicing an indexing works with tuples just like it works with strings,

3
00:00:17,490 --> 00:00:19,545
lists or other kinds of sequences.

4
00:00:19,545 --> 00:00:21,660
So here we have a tuple, Julia,

5
00:00:21,660 --> 00:00:25,485
with a few items, some strings, some integers.

6
00:00:25,485 --> 00:00:28,570
On line two, we print out Julia sub two.

7
00:00:28,570 --> 00:00:30,860
If we want to determine what that prints out,

8
00:00:30,860 --> 00:00:33,875
we first need to determine what kind of operation this is.

9
00:00:33,875 --> 00:00:37,250
So, we see that we're saying Julia sub and

10
00:00:37,250 --> 00:00:40,910
so that should tell us that we're either indexing or slicing.

11
00:00:40,910 --> 00:00:43,135
I don't see a colon here,

12
00:00:43,135 --> 00:00:45,870
so that should tell me that this is indexing.

13
00:00:45,870 --> 00:00:48,550
So, when I print out Julia sub two,

14
00:00:48,550 --> 00:00:50,825
that's going to print out the third item.

15
00:00:50,825 --> 00:00:53,870
Again, the third item because we're zero indexed.

16
00:00:53,870 --> 00:00:56,885
So, the third item is zero,

17
00:00:56,885 --> 00:01:02,700
this is one, this is two and so this should be 1967.

18
00:01:05,330 --> 00:01:09,600
Then we print out Julia sub two through six.

19
00:01:09,600 --> 00:01:12,235
So, in order to determine what that prints out,

20
00:01:12,235 --> 00:01:21,830
I'm going to write the indices on the edges of the items; six.

21
00:01:21,830 --> 00:01:27,590
So, two through six is going to be, two through six,

22
00:01:27,590 --> 00:01:31,585
and so that should be everything from 1967

23
00:01:31,585 --> 00:01:37,950
through actress and that's what this slide should print out.

24
00:01:37,950 --> 00:01:43,465
When we print out the length of Julia then that's going to ask how many items are there.

25
00:01:43,465 --> 00:01:46,920
So I see there's zero, one, two,

26
00:01:46,920 --> 00:01:52,650
three, four, five, six.

27
00:01:52,650 --> 00:01:54,440
Don't get fooled by the comma here,

28
00:01:54,440 --> 00:01:56,765
it's actually part of the string not part of

29
00:01:56,765 --> 00:02:01,410
the tuple definition and so that's going to say that there are one,

30
00:02:01,410 --> 00:02:04,980
two, three, four, five, six, seven items.

31
00:02:04,980 --> 00:02:06,855
If the last index is six,

32
00:02:06,855 --> 00:02:08,625
then because there's a zero here,

33
00:02:08,625 --> 00:02:11,830
then that means that the length is seven.

34
00:02:12,140 --> 00:02:16,549
Then here we have a complicated concatenation operation.

35
00:02:16,549 --> 00:02:21,560
So, first we take Julia sub from the beginning through item

36
00:02:21,560 --> 00:02:27,160
three and so that's going to be Julia Roberts 1967.

37
00:02:27,160 --> 00:02:43,290
So let me write that out. Julia Roberts 1967.

38
00:02:43,290 --> 00:02:47,715
Then we concatenate to the string Eat Pray Love in 2010.

39
00:02:47,715 --> 00:02:51,060
So, Eat, Pray,

40
00:02:51,060 --> 00:03:00,880
Love and 2010 and then we add Julia from index five on.

41
00:03:00,880 --> 00:03:05,010
So that's going to be everything from actress on.

42
00:03:05,010 --> 00:03:07,360
So that's Actress

43
00:03:09,480 --> 00:03:16,160
and Atlanta, Georgia.

44
00:03:18,600 --> 00:03:26,775
I just add commas between these and this gives us a tuple back.

45
00:03:26,775 --> 00:03:30,745
So, this is what I expect to print when we run this code.

46
00:03:30,745 --> 00:03:33,440
Let's test our hypotheses.

47
00:03:33,900 --> 00:03:40,730
Okay, so I see that line two does indeed print out 1967,

48
00:03:40,730 --> 00:03:47,605
line three does in fact print out everything from 1967 through actress,

49
00:03:47,605 --> 00:03:50,590
line five does in fact print out

50
00:03:50,590 --> 00:03:59,100
seven and line eight does in fact print out this list that we specified.

51
00:03:59,440 --> 00:04:04,950
So, let's go over some questions related to slicing and indexing.

52
00:04:05,210 --> 00:04:07,240
So first if we ask,

53
00:04:07,240 --> 00:04:09,920
what's printed out by the following statement?

54
00:04:09,920 --> 00:04:18,235
So, the string S is Python rocks and we print out S from index 3-8.

55
00:04:18,235 --> 00:04:21,980
So, in order to determine what actually gets printed out,

56
00:04:21,980 --> 00:04:25,825
then I'm going to first find out where index three is,

57
00:04:25,825 --> 00:04:30,375
so this is zero, one, two, three.

58
00:04:30,375 --> 00:04:34,610
So, what that means is that because we include index three,

59
00:04:34,610 --> 00:04:41,540
I'm going to draw a line right here and then we print out that through eight, four,

60
00:04:41,540 --> 00:04:49,390
five, six, seven, eight but we don't include index eight because

61
00:04:49,390 --> 00:04:53,170
we move kind of all of these dots to the left and so what that

62
00:04:53,170 --> 00:04:57,040
means is that we're going to get everything from here to here.

63
00:04:57,040 --> 00:05:01,430
So, we should get hon space r or item

64
00:05:01,430 --> 00:05:07,915
C. Okay, next question.

65
00:05:07,915 --> 00:05:14,500
So here we have a list that has a mix of some integers,

66
00:05:14,500 --> 00:05:20,540
some strings and some actual other lists as items.

67
00:05:20,540 --> 00:05:24,810
So what we're asking is what's printed by the following statement.

68
00:05:24,810 --> 00:05:29,080
So we create this list and we print out a list sub four colon.

69
00:05:29,080 --> 00:05:31,370
So in order to figure that out,

70
00:05:31,370 --> 00:05:33,740
and I'm going to first find index four,

71
00:05:33,740 --> 00:05:34,950
so we have zero,

72
00:05:34,950 --> 00:05:38,910
one, two, three, four.

73
00:05:38,910 --> 00:05:41,950
So, index four contains

74
00:05:41,950 --> 00:05:45,700
this empty list and because we don't have anything after the colon,

75
00:05:45,700 --> 00:05:49,030
then we're saying we want everything from index four on

76
00:05:49,030 --> 00:05:53,005
and so we can draw a kind of a line here and we know that

77
00:05:53,005 --> 00:05:57,250
it's going to contain everything from this empty list to

78
00:05:57,250 --> 00:06:03,080
3.14 to false and so I expect the answer would be A.

79
00:06:03,900 --> 00:06:08,680
We can see that answer A here was the correct answer.

80
00:06:08,680 --> 00:06:12,190
Okay. So now we have a question asking us to create

81
00:06:12,190 --> 00:06:16,150
a new list using the ninth through 12th items.

82
00:06:16,150 --> 00:06:21,640
So, four items in all of new list and assign it to the variable sublist.

83
00:06:21,640 --> 00:06:26,530
The first thing I'm going to do in order to answer this question is I'm going to say

84
00:06:26,530 --> 00:06:32,890
sublist equals and then I know I'm going to be slicing on new list.

85
00:06:32,890 --> 00:06:40,030
So, I'm going to say sublist equals new list sub.

86
00:06:40,030 --> 00:06:44,080
If we want the ninth item then we actually have to use index eight.

87
00:06:44,080 --> 00:06:48,970
So, I'm going to say index eight and because I want a subset then I want to slice,

88
00:06:48,970 --> 00:06:50,410
so I use the colon.

89
00:06:50,410 --> 00:06:52,855
I went through the 12th item.

90
00:06:52,855 --> 00:06:57,280
So, if we include index eight, nine, 10,

91
00:06:57,280 --> 00:07:02,165
11, then that's going to give us four items.

92
00:07:02,165 --> 00:07:04,025
So, what I want to say is,

93
00:07:04,025 --> 00:07:10,725
I went through but not including index 12 because that's actually the 13th item,

94
00:07:10,725 --> 00:07:13,160
because again, Python is zero indexed.

95
00:07:13,160 --> 00:07:20,105
So if I say sublist equals new list from indices eight through 12 and run it,

96
00:07:20,105 --> 00:07:22,255
then I get the correct answer.

97
00:07:22,255 --> 00:07:25,660
That's all for now, until next time.