WEBVTT 00:02.830 --> 00:09.490 In this review we will learn what slices and maps are less than maps are data structures that hold a 00:09.490 --> 00:15.830 collection of values a slice is not about a collection of elements of the same type. 00:15.960 --> 00:20.880 And they look like this open and close bracket type. 00:21.620 --> 00:27.540 Let's use it open square brackets and the items or elements. 00:27.670 --> 00:30.910 Let's say I have these numbers and 13. 00:31.050 --> 00:34.110 So I need to assign this to some variables. 00:34.120 --> 00:36.910 So let's do number equals to this. 00:37.140 --> 00:37.950 Okay. 00:38.320 --> 00:43.210 Now let's print it to see how it looks like and I have my slice of numbers. 00:43.210 --> 00:52.920 Now as this slice is typed I come up a string here because if I do it the compiler will tell me that 00:52.930 --> 01:00.130 there is an error and the error is I can convert twenty one between quotes which is a string to the 01:00.130 --> 01:01.150 type end. 01:01.690 --> 01:10.530 So remember that when you're doing this all the elements has to be defined in the same type. 01:11.070 --> 01:11.490 Okay. 01:11.880 --> 01:15.210 Now reference elements in disarray. 01:15.240 --> 01:19.610 I will use the square bracket notation I opened square bracket. 01:19.740 --> 01:22.790 I reference the position and I close the square brackets. 01:22.850 --> 01:25.310 Now I'm pointing to the first element. 01:25.320 --> 01:33.780 It's important to know that slices use this index starting from zero to these no one is going to be 01:33.780 --> 01:35.730 in the position zero. 01:35.790 --> 01:41.640 The second number is gonna be in the position one third number is going to be in the position too and 01:41.640 --> 01:42.240 so on. 01:42.660 --> 01:50.850 So if I want to last the last element I'm gonna do numbers sub six. 01:50.910 --> 01:55.110 Now let's say you want to access the position 100 which doesn't exist. 01:55.120 --> 01:56.320 What do you think will happen. 01:56.320 --> 02:00.910 Well I have an error and the error is index which is a hundred. 02:01.090 --> 02:07.740 It's out of range because my slice has just seven element. 02:07.740 --> 02:12.630 So how do I know how many elements does my slice has. 02:12.630 --> 02:19.710 We have a function for that which is called Len in words like this Len of numbers it's gonna be seven 02:20.620 --> 02:24.280 but it's important to in order to access the last element. 02:24.510 --> 02:29.190 I don't use 7 but six because index starting at zero. 02:29.550 --> 02:36.250 So if I want to print the last number of my array of my lines I can do number six. 02:36.270 --> 02:39.530 Are we just so or numbers stop. 02:39.570 --> 02:46.650 Len minus 1 and various not well-defined numbers. 02:46.650 --> 02:47.400 No it's fine. 02:47.590 --> 02:48.830 And I have the last element. 02:49.220 --> 02:49.930 OK. 02:50.160 --> 02:53.120 Now to traverse this slice. 02:53.520 --> 02:59.190 We can use what we've learned in the previous episode which is the for keyword. 02:59.340 --> 03:03.490 So we'll do it by these four range numbers. 03:03.660 --> 03:08.400 Now range number will return to values for each iteration. 03:08.400 --> 03:13.050 The first one is the index and the second one is the value. 03:13.050 --> 03:21.810 So now let's bring the content of those variables in the will be index value will be value and let me 03:21.810 --> 03:26.000 remove this line which is really important right now I made a mistake. 03:26.040 --> 03:26.480 Yeah. 03:26.510 --> 03:27.750 Missing a coin here. 03:27.870 --> 03:29.930 Because two different arguments. 03:30.000 --> 03:38.990 OK so now I have as we saw in the code here possible zero or index zero value one in this one value 03:38.990 --> 03:45.140 one index two values to index three value three and now indexed for value five. 03:45.140 --> 03:51.250 Index 5 value 8 index 6 value 13 the same as we can see here. 03:51.320 --> 03:52.450 Right. 03:52.640 --> 03:57.720 This is pretty useful when you want to use these iterate over this array. 03:57.800 --> 04:03.590 Now let's say you just want the bodies and I don't want the index it's just as easy as use underscore 04:03.620 --> 04:12.240 here to ignore them variable and just print the value right and of course they can do the same. 04:13.570 --> 04:20.830 For index let's say I don't one day in this and I just want the volume so I nor with underscore that 04:20.830 --> 04:23.230 value and I remove it from here. 04:23.470 --> 04:25.800 So I'm just caught up in the index now. 04:25.840 --> 04:33.340 Right now another property for number four slices is that I can add extra values to it. 04:33.580 --> 04:41.990 So let's say I have these numbers and I want to upend the number hundred and of the slice. 04:42.400 --> 04:44.930 I will do it by call a pen. 04:45.150 --> 04:50.090 The first argument is gonna be the line with his numbers and then I get the extra value which is going 04:50.090 --> 04:51.260 to be a hundred. 04:51.620 --> 04:59.920 So now what I'm doing is printing the numbers within append the extra value of one hundred and I have 05:01.180 --> 05:05.340 the numbers which is from 1 to 13 plus an extra hundred. 05:05.410 --> 05:14.110 Now a pen supports a dynamic number of arguments like another 100 hundred Here are nine fifty and so 05:14.110 --> 05:14.400 on. 05:14.620 --> 05:20.650 And if I print these now I'm gonna get the original numbers plus the one that I have on it. 05:20.770 --> 05:28.040 So yeah now let's see what maps are for maps. 05:28.400 --> 05:34.700 It's kind of similar to slices but they are on all that a collection of key value items. 05:34.960 --> 05:41.780 They are also known in other languages as associative arrays House tables or dictionaries have a better 05:41.780 --> 05:43.350 understanding of them. 05:43.400 --> 05:51.530 They looks like a table like Excel table where the first column eats a key and the second one is in 05:51.530 --> 05:52.050 value. 05:52.700 --> 05:57.860 It's just a key value pair it's always a pair pull there's always gonna be a key and there's always 05:57.860 --> 05:58.740 gonna be a value. 05:59.240 --> 06:06.500 So let's say this is my user table I will have three keys and three values. 06:06.770 --> 06:13.400 So how should I define this not by using the map keyword between brackets square brackets I'm going 06:13.400 --> 06:20.540 to define the type of the key using string and then the type of the value let's use a string as well 06:20.570 --> 06:24.320 because here I'm just using strings. 06:24.410 --> 06:29.070 Now I can open and close to curly brackets to define the values. 06:29.210 --> 06:34.690 The key is going to be on the first place let's say name column value. 06:34.760 --> 06:38.850 In this case study and after I need two other trailing columns. 06:39.710 --> 06:42.550 So let's do the same for the other elements. 06:42.790 --> 06:51.110 E-mail is gonna be double our company that come and finally Row developer. 06:51.930 --> 06:52.750 OK. 06:52.760 --> 06:56.340 Now I have this letter saying that you are variable. 06:56.580 --> 07:03.600 So now my user variable points to a map of string keys and string values. 07:04.080 --> 07:04.800 Let's drink this. 07:04.800 --> 07:06.290 See how it looks like. 07:06.680 --> 07:07.040 OK. 07:07.140 --> 07:08.650 No errors. 07:08.870 --> 07:17.340 Can I have my map with three items or elements using string keys as a string of values. 07:17.350 --> 07:23.390 Now let's say I want to access a specific item in this map. 07:23.760 --> 07:29.840 I'll do it by call coal users open square brackets and the key. 07:29.840 --> 07:36.030 So I want to bring the email is using and I have it right now. 07:36.070 --> 07:36.800 What happened. 07:37.220 --> 07:45.440 If I reference a non-existent key so let's say I really want to get the age of these user but it's not 07:45.440 --> 07:46.490 defined right. 07:46.490 --> 07:52.970 I get an empty string so I can either define it like age 30. 07:53.180 --> 07:59.930 Now I should print and write but if I don't have it how can I know that the age is not defined. 08:00.530 --> 08:09.020 So for that we use the decimal with it here but instead of assigning into a single variable we will 08:09.020 --> 08:11.440 use a couple of miles. 08:11.450 --> 08:14.140 So this is very interesting. 08:14.210 --> 08:18.590 If I use a variable a single one I'm just getting the value if it exists. 08:18.640 --> 08:20.990 Otherwise I just get an empty string. 08:21.040 --> 08:24.040 But if I used to write this here I can verify. 08:24.110 --> 08:25.150 OK. 08:25.190 --> 08:26.580 Is true. 08:26.810 --> 08:31.680 So I'll print H age right. 08:31.740 --> 08:36.190 Health or otherwise is OK was false. 08:36.200 --> 08:39.400 I can print age. 08:39.470 --> 08:42.030 Not fun right. 08:42.560 --> 08:45.740 So I reference the age here. 08:45.960 --> 08:48.030 I assigning into the age variable. 08:48.060 --> 08:52.470 But the second one is just gonna be true or false depending if age were defined. 08:52.770 --> 08:54.860 So it says age is not found. 08:54.870 --> 08:58.070 Now let's define age and see what happens. 08:58.230 --> 08:59.290 Great is there. 08:59.310 --> 09:03.170 Now remember the tea cup is case sensitive. 09:03.210 --> 09:12.310 So we if here age is the capital a he's gonna be on phone anyway so I will need to make it the same 09:12.310 --> 09:13.500 in every case. 09:13.540 --> 09:13.860 Okay. 09:15.020 --> 09:20.990 Finally if I want to add some extra data to the user I can do it like this. 09:21.450 --> 09:32.100 And now these were well and the functions that we solve for the license for traversing nice oh also 09:32.100 --> 09:32.640 works. 09:32.640 --> 09:46.830 So if I do for key value call on equal to rage user I will be able to see the value and the keeper on 09:46.830 --> 10:01.240 every iteration of Green Line key key and volume value I have here key role. 10:01.260 --> 10:06.020 Value developer key name volumes tell and so on. 10:06.030 --> 10:13.380 Now it's important to note that every time that I printed this the order of the key are different. 10:13.380 --> 10:16.480 So here I have a name email and roll. 10:16.740 --> 10:20.430 But before I have row name an email. 10:20.430 --> 10:30.950 So these are very important different between maps and slices slices are ordered while maps are not. 10:31.750 --> 10:37.350 So yeah this is the most important thing about maps and slices. 10:37.500 --> 10:44.160 They are pretty much complex that I've just explained to you but those details are not part of this 10:44.790 --> 10:45.270 course. 10:45.540 --> 10:52.490 So if you want to dig more and get more information about them go to the goal of official documentation 10:52.490 --> 10:59.970 and you will see a very complete document that explain how the words and other possibilities that you 10:59.970 --> 11:01.860 have when working with them.