1 00:00:07,880 --> 00:00:11,810 Let's suppose you want to make a clone of a list, 2 00:00:11,810 --> 00:00:13,425 not an alias for it. 3 00:00:13,425 --> 00:00:18,470 You want another variable that will have an equivalent lists, 4 00:00:18,470 --> 00:00:22,080 a copy of the original list or a clone of the original list, 5 00:00:22,080 --> 00:00:25,180 but you want the two lists to be independent. 6 00:00:25,370 --> 00:00:29,850 Let's say we start with a list a, 7 00:00:29,850 --> 00:00:32,700 that has the elements 81, 82, and 83. 8 00:00:32,700 --> 00:00:35,100 We want to make a new variable b, 9 00:00:35,100 --> 00:00:37,590 that has a clone or a copy of it. 10 00:00:37,590 --> 00:00:43,059 We can do that using the slice operator, the slice operator, 11 00:00:43,250 --> 00:00:47,525 always grabs some part of a list, 12 00:00:47,525 --> 00:00:53,980 and makes a new list using those items that have been grabbed using the slice. 13 00:00:53,980 --> 00:00:57,240 So, if we execute this in code, 14 00:00:57,240 --> 00:00:59,710 then we can see what happens. 15 00:01:01,010 --> 00:01:04,065 So, we created a list a, 16 00:01:04,065 --> 00:01:06,905 we make a slice, 17 00:01:06,905 --> 00:01:11,020 in this case our slice begins at the beginning of 18 00:01:11,020 --> 00:01:15,175 the list and goes all the way to the end of the list. 19 00:01:15,175 --> 00:01:17,320 So, we get all three items, 20 00:01:17,320 --> 00:01:18,840 zero, one, and two, 21 00:01:18,840 --> 00:01:21,830 and they are copied into a new list, 22 00:01:25,980 --> 00:01:29,520 and so we get a new list, 23 00:01:29,520 --> 00:01:32,250 so b is now not an alias for a, 24 00:01:32,250 --> 00:01:37,795 b is referring to a list with equivalent contents, the same contents. 25 00:01:37,795 --> 00:01:42,720 So, if we print a equal equals b, they are equivalent, 26 00:01:42,720 --> 00:01:45,885 so that's true, but a is not b, 27 00:01:45,885 --> 00:01:47,895 they're pointing to different lists. 28 00:01:47,895 --> 00:01:53,100 Now, if I change b sub zero to be five, 29 00:01:53,100 --> 00:01:57,670 unlike our previous example where b was an alias for a, 30 00:01:57,670 --> 00:02:00,115 when b sub zero is set to five, 31 00:02:00,115 --> 00:02:03,010 only b is going to be affected. 32 00:02:03,010 --> 00:02:08,985 So, we see that it has a new value five, 33 00:02:08,985 --> 00:02:13,600 but the 81 is still there for a zero. 34 00:02:14,660 --> 00:02:19,615 So, when I print a, I'll get the original list, 35 00:02:19,615 --> 00:02:25,750 b was originally an equivalent lists with the same contents, 36 00:02:25,750 --> 00:02:28,600 a clone of a, they've become independent and 37 00:02:28,600 --> 00:02:33,580 b gets mutated without having any effect on a. 38 00:02:33,580 --> 00:02:39,885 There you have it, clonal list by using the slice operator, 39 00:02:39,885 --> 00:02:44,695 if you don't say, either a beginning or an ending index, 40 00:02:44,695 --> 00:02:51,870 you get the whole list and you get a clone or a copy of the list.