1 00:00:01,110 --> 00:00:07,230 So far you have learned some of the main data types available in platform that are not he didn't truths 2 00:00:07,230 --> 00:00:09,190 about integers or floats. 3 00:00:09,360 --> 00:00:16,740 But there may be a few things you need to know about sequences such as lease and tuples and strings 4 00:00:16,740 --> 00:00:17,820 as well. 5 00:00:17,820 --> 00:00:20,800 So that's what I'll explain in this lecture. 6 00:00:20,820 --> 00:00:25,500 First let's talk about indexing streams support indexing. 7 00:00:25,800 --> 00:00:27,580 Just like some tables. 8 00:00:27,900 --> 00:00:33,580 So let me generate a quick least using a list function and the range function as well. 9 00:00:33,960 --> 00:00:39,900 So I'll store my list in my file this valuable and I write the list function. 10 00:00:40,170 --> 00:00:45,300 So those functions generate a list object then to the Lisp function. 11 00:00:45,300 --> 00:00:51,870 I'll pass a range function and then to the range function I'll pass a range of numbers starting from 12 00:00:51,870 --> 00:00:59,790 2000 and ending at 2020 with the step of two. 13 00:00:59,810 --> 00:01:02,280 And here is the list. 14 00:01:02,320 --> 00:01:06,370 Now I'll quickly teach you how to access certain parts of the list. 15 00:01:07,250 --> 00:01:14,240 So first we're going to access a single item of values that we are going to access a certain slice of 16 00:01:14,240 --> 00:01:14,820 the list. 17 00:01:15,030 --> 00:01:22,550 Then all of the first three items then all the items are for the second item and only the last two items 18 00:01:22,580 --> 00:01:29,430 of the list to understand them and perform those actions you should already know how the items are the 19 00:01:29,440 --> 00:01:30,750 least indexed. 20 00:01:30,980 --> 00:01:39,590 So each item of the list is hiding a certain index underneath indexes start from zero and increment 21 00:01:39,590 --> 00:01:40,290 by 1. 22 00:01:40,520 --> 00:01:43,150 So the first line item has an index of zero. 23 00:01:43,420 --> 00:01:47,780 The second item as an index of one and so on. 24 00:01:47,780 --> 00:01:51,240 Now let's start by accessing an item of the list. 25 00:01:51,260 --> 00:01:56,590 Let's say I want the third item because the counting starts from zero. 26 00:01:56,630 --> 00:02:02,060 Index off of the third item is to see syntax is this. 27 00:02:02,060 --> 00:02:08,810 We write the variable name that contains a list and then we write the index inside square brackets. 28 00:02:08,810 --> 00:02:10,760 Now let's see it by four returns. 29 00:02:10,760 --> 00:02:17,100 The third item of the list the fourth element you'd need an index or three. 30 00:02:17,120 --> 00:02:24,070 And so one know sometimes you might need to access more than one element of the list. 31 00:02:24,070 --> 00:02:35,660 Let's say you want all that part of the least that's towards 2002 and 2010 including 2010 to extract 32 00:02:35,660 --> 00:02:37,650 such a slice from families. 33 00:02:37,790 --> 00:02:45,260 You need to know the index of the lower and upper Bollen numbers of the slice that we want in this case. 34 00:02:45,260 --> 00:02:49,540 They are index 1 and 5. 35 00:02:49,790 --> 00:02:51,160 The syntax is this. 36 00:02:51,360 --> 00:03:01,520 So the name of the list the square brackets the index of the first number column an index of the number 37 00:03:01,520 --> 00:03:04,560 or for the upper bound number or the slice. 38 00:03:04,850 --> 00:03:09,220 So why is the number after the upper bar number you'd ask. 39 00:03:09,650 --> 00:03:17,150 Well the answer is that the slices and oranges are upper bound exclusive meaning that the number identified 40 00:03:17,150 --> 00:03:20,460 by the last index is not included in this list. 41 00:03:20,480 --> 00:03:26,090 So if you write five year of slice you will not include the item with index 5. 42 00:03:26,150 --> 00:03:34,070 Therefore we tried six to include the the number with ex-wife and we have our slice. 43 00:03:34,070 --> 00:03:41,060 Sometimes you might want to access only the first three elements or at least for example and you could 44 00:03:41,060 --> 00:03:47,860 do that using zero has a lower bound index and three as upper one however. 45 00:03:47,900 --> 00:03:56,800 A quicker way to do that is to just use the last index without explicitly writing the number 0. 46 00:03:56,850 --> 00:04:05,070 So it's just like saying OK Python give me everything before three including three if you want us a 47 00:04:05,070 --> 00:04:12,780 slice consisting of all the items after the second night of the list you would need to write two and 48 00:04:12,780 --> 00:04:14,850 a column inside the square brackets. 49 00:04:15,210 --> 00:04:17,640 So this is like OK Python. 50 00:04:17,670 --> 00:04:21,090 Now give me everything of the two. 51 00:04:21,270 --> 00:04:32,710 And if you want the last two items of the least you could count like 0 1 2 3 4 5 6 7 8 and tell them 52 00:04:32,730 --> 00:04:35,570 to give you everything right including 8. 53 00:04:36,060 --> 00:04:39,240 But hey don't you find this a bit stupid. 54 00:04:39,480 --> 00:04:43,770 Counting from the start when you won the last two items. 55 00:04:43,980 --> 00:04:44,340 Sure. 56 00:04:44,340 --> 00:04:49,350 That's a bit Silverlink That's why a second indexing convention exists along. 57 00:04:49,470 --> 00:04:53,830 The first one starts at zero and incrementing by 1. 58 00:04:53,850 --> 00:04:58,900 So this second indexing I'm talking about starts at minus 1. 59 00:04:59,190 --> 00:05:03,640 The upper bound of the list and decreases by 1. 60 00:05:03,750 --> 00:05:11,330 So minus one for the first item starting from the upper bound minus 2 for the second item. 61 00:05:11,670 --> 00:05:13,100 And so on. 62 00:05:13,110 --> 00:05:17,910 So if we want the last two items of the list we don't need to count. 63 00:05:18,360 --> 00:05:19,920 We just can't tell a python. 64 00:05:19,920 --> 00:05:27,750 Give me everything up to minus two including minus two and if you want a slice that excludes the last 65 00:05:27,750 --> 00:05:34,890 two items you could tell by phone hey give me everything before minus two including minus two. 66 00:05:35,310 --> 00:05:37,150 That's it. 67 00:05:37,150 --> 00:05:40,870 Now these were all loose slicing operations. 68 00:05:41,120 --> 00:05:45,720 You could apply the exact same operations to streaks so. 69 00:05:46,060 --> 00:05:55,360 So if you have a string of let's say something and I'm going to store it in a variable the same indexing 70 00:05:55,360 --> 00:05:57,560 conventions applied to things. 71 00:05:57,580 --> 00:06:05,350 So if you want the fourth character you're right the variable than the index inside those square brackets 72 00:06:06,130 --> 00:06:13,860 which is three I'll let you practice the rest of the slicing operations with strings on your own pace. 73 00:06:14,120 --> 00:06:18,590 Now towboats do not escape from the circles either. 74 00:06:18,610 --> 00:06:24,810 So we have this table and I'm going to extract the last item only. 75 00:06:25,510 --> 00:06:30,510 And by phone gives you everything golfer minus on including minus one. 76 00:06:30,530 --> 00:06:32,530 I hope that was clear. 77 00:06:32,590 --> 00:06:37,590 That's what I wanted to teach you about slicing leasts strings and total's.