1 00:00:00,000 --> 00:00:04,600 Let's talk about another data type, lists, which are also a sequence. 2 00:00:04,680 --> 00:00:11,660 A list is literally just a list, but we have a few different 3 00:00:11,660 --> 00:00:13,400 types in Python. We have this one called a list; 4 00:00:13,470 --> 00:00:15,560 we have another one called a tuple or a tuple, 5 00:00:15,560 --> 00:00:18,100 some people call it a tuple; and a set. 6 00:00:18,800 --> 00:00:21,500 These are the three main ones you're usually going to work 7 00:00:21,500 --> 00:00:22,800 with in Python code. 8 00:00:22,840 --> 00:00:28,180 Now, these lists or these type of sequences, you can think 9 00:00:28,180 --> 00:00:32,100 of them as a 'grocery', 'Grocery list'. 10 00:00:32,100 --> 00:00:36,700 So you're going to the store and you have to pick up milk, bread and eggs, 11 00:00:36,700 --> 00:00:39,390 And I've made this metaphor a few times now, but you've got 12 00:00:39,400 --> 00:00:43,380 milk, bread and eggs. And you walk into the store and you're 13 00:00:43,380 --> 00:00:46,200 like, "Oh, Hey, I'm going to pick up milk, cross it off your list. 14 00:00:46,200 --> 00:00:48,000 I am going to go pick up eggs, 15 00:00:48,020 --> 00:00:49,370 cross that off your list. 16 00:00:49,370 --> 00:00:51,600 I'm going to go pick up bread, 17 00:00:51,620 --> 00:00:55,310 and you cross that off your list. That's all these are doing. 18 00:00:55,490 --> 00:00:58,170 So let's actually turn this into code. 19 00:00:58,170 --> 00:01:02,600 So a list starts with and ends with these hard brackets, '[]' 20 00:01:02,680 --> 00:01:04,720 And I just made that one step bigger there. 21 00:01:04,730 --> 00:01:06,860 And you could say 'Milk', 22 00:01:06,870 --> 00:01:08,330 and that's a string. 23 00:01:08,330 --> 00:01:09,900 You could say 'Eggs'. 24 00:01:09,900 --> 00:01:11,000 That's also a string. 25 00:01:11,000 --> 00:01:12,700 'Bread'. That's also a string. 26 00:01:12,750 --> 00:01:16,700 And remember, each one of these is also a sequence, but it 27 00:01:16,700 --> 00:01:21,000 is also its own item in this list, in this array. 28 00:01:21,020 --> 00:01:24,050 And then just for funsies, I want to show you that we can 29 00:01:24,050 --> 00:01:25,700 also use a number, 30 00:01:25,700 --> 00:01:29,900 so let's say the number 42; and a Boolean. 31 00:01:29,900 --> 00:01:34,300 And if I just display this, 'groceries', we can see we've got 32 00:01:34,300 --> 00:01:36,300 '['Milk', 'Eggs', 'Bread', 42, and True]'. 33 00:01:36,300 --> 00:01:39,300 Now I'm going to create this thing called a for loop. 34 00:01:39,340 --> 00:01:41,080 You don't need to know what that is right now. 35 00:01:41,090 --> 00:01:43,840 You don't need to understand how it works or the syntax behind 36 00:01:43,850 --> 00:01:45,790 it, because this is just for a demonstration. 37 00:01:45,800 --> 00:01:49,300 We'll get into loops down the road and we'll get some proper 38 00:01:49,310 --> 00:01:50,860 education around that as well. 39 00:01:50,870 --> 00:01:53,710 But for now, this is just going to be a demonstration. 40 00:01:53,710 --> 00:01:58,000 So 'for item in groceries', 41 00:01:58,020 --> 00:02:03,510 and because this is a sequence or a list, it's going to go 42 00:02:03,520 --> 00:02:05,460 through 'Milk', 'Eggs', 'Bread', 42, 43 00:02:05,460 --> 00:02:08,758 and True. And so what I'm doing here, is I'm just saying for 44 00:02:08,770 --> 00:02:11,940 each one of these, whatever it's called in here, 'Milk', 'Eggs', 45 00:02:11,940 --> 00:02:15,300 'Bread', 42 or True, just call it an 'item'. 46 00:02:15,300 --> 00:02:18,200 And so that is a variable called 'item'. 47 00:02:18,280 --> 00:02:20,200 And I can just print that. 48 00:02:20,900 --> 00:02:25,800 And when I run this, 'Milk', 'Eggs', 'Bread', 42 and True. And now 49 00:02:25,890 --> 00:02:30,110 if we want to, we can actually change this to be a tuple. 50 00:02:31,200 --> 00:02:34,400 So let's rerun the cell, this cell, 51 00:02:34,400 --> 00:02:36,300 and you can see that the brackets changed here as well, 52 00:02:36,340 --> 00:02:37,260 so we know it's a tuple. 53 00:02:37,550 --> 00:02:42,040 And when I rererun the for loop, it looks like nothing happened, 54 00:02:42,040 --> 00:02:44,400 but that's because it just has the same items in there. 55 00:02:44,400 --> 00:02:47,100 We can even do the same thing with a set. 56 00:02:47,440 --> 00:02:50,110 And a set looks almost identical. 57 00:02:50,110 --> 00:02:54,900 But let's go ahead and add 'Bread' for a second time, and also 58 00:02:54,960 --> 00:02:56,520 'Milk' for a second time. 59 00:02:56,520 --> 00:02:59,700 So we've got 'Milk', 'Eggs', 'Bread', 'Bread', 'Milk', 42, and True. 60 00:02:59,780 --> 00:03:01,580 Let's run that and run this. 61 00:03:01,590 --> 00:03:04,790 And now you can actually see that it's not in any particular 62 00:03:04,800 --> 00:03:09,600 order, but 'Bread' and 'Milk' only show up once, whereas up here 63 00:03:09,610 --> 00:03:10,680 it was specified twice. 64 00:03:10,690 --> 00:03:14,010 So that's the difference between a set and a list. A set 65 00:03:14,020 --> 00:03:15,870 makes sure that every item in there is unique. 66 00:03:15,880 --> 00:03:18,480 So you have 42, 'Bread', 'Eggs', 'Milk', and True. 67 00:03:18,660 --> 00:03:20,100 It is also a sequence, 68 00:03:20,110 --> 00:03:23,560 so when we rerun this instead of saying 'Bread' twice and 'Milk' 69 00:03:23,560 --> 00:03:28,570 twice, it only shows up with 'Milk' and 'Bread' once because 70 00:03:28,570 --> 00:03:30,800 it's unique to that particular sequence. 71 00:03:30,860 --> 00:03:33,680 Now, one thing to keep in mind here is that this sequence 72 00:03:33,690 --> 00:03:35,510 did not keep its order at all. 73 00:03:35,520 --> 00:03:37,520 It started with 'Milk', 'Eggs', and 'Bread', 74 00:03:37,520 --> 00:03:40,610 and then for whatever reason, when Python internalized this, 75 00:03:40,610 --> 00:03:45,800 it went to 42, 'Bread', 'Eggs', and then even in our for loop, 76 00:03:45,860 --> 00:03:48,530 when we just wanted to print back all these different items 77 00:03:48,540 --> 00:03:52,280 on their own lines, it started with - True, 'Bread', 42. 78 00:03:52,290 --> 00:03:54,050 So none of those actually match up. 79 00:03:54,060 --> 00:03:55,340 So it didn't keep their order. 80 00:03:55,400 --> 00:03:57,860 So if you need something to absolutely keep their order, 81 00:03:57,860 --> 00:04:01,480 definitely use a tuple, which has the softer parentheses, 82 00:04:01,600 --> 00:04:04,100 brackets; run, run, run; 83 00:04:04,860 --> 00:04:06,090 and that keeps its order. 84 00:04:06,270 --> 00:04:13,280 Or you can use the list with the harder brackets; run, run, run; 85 00:04:13,700 --> 00:04:15,600 and get the exact same results. 86 00:04:15,600 --> 00:04:20,899 So that is lists and lists like sequences in a nutshell. 87 00:04:20,899 --> 00:04:24,399 Now that you sort of understand what those kind of look like 88 00:04:24,399 --> 00:04:26,500 a little bit, let's move on to the next one.