1 00:00:00,740 --> 00:00:04,390 So overcoming Jane this listening is actually a quick exercise. 2 00:00:04,430 --> 00:00:10,920 And along with this lesson I have provided you with an array which includes the names of so many many 3 00:00:10,920 --> 00:00:17,730 different cities and within those there is are several copies of the name Vancouver. 4 00:00:17,730 --> 00:00:23,650 So they want you to do is I want you to write a program that can find out how many copies of Vancouver 5 00:00:23,710 --> 00:00:25,240 are within the array. 6 00:00:25,500 --> 00:00:28,200 So post the video now try on your own. 7 00:00:28,210 --> 00:00:34,440 Try to iterate through all the elements of the array and count the number of occurrences of Vancouver 8 00:00:34,680 --> 00:00:41,280 and print at the end and then once you are done you can you know playback the video again and find out 9 00:00:41,310 --> 00:00:47,460 if your solution is right or if you are the better solution or if there are things that we don't quite 10 00:00:47,460 --> 00:00:48,500 manage to complete. 11 00:00:48,630 --> 00:00:50,960 So let's pause the video now and then continue. 12 00:00:54,110 --> 00:00:55,780 So here's how I'm going to do it. 13 00:00:55,780 --> 00:00:57,560 Let's jump back into ex-cult 14 00:01:00,570 --> 00:01:10,000 I'm going to start in your project I'm going to call Ed Curran says exercise. 15 00:01:10,290 --> 00:01:14,140 If that's how you spell occurrence I hope so. 16 00:01:14,150 --> 00:01:24,920 I'm also going to go with that and clean things up as usual to get a better formatting by dot. 17 00:01:25,080 --> 00:01:30,330 I'm also going to the file that you have received with this lesson and get a copy of that. 18 00:01:30,340 --> 00:01:33,610 So that's a copy and paste it here. 19 00:01:33,720 --> 00:01:40,800 So I have an array with so many many different cities around the Vancouver once twice three times four 20 00:01:40,800 --> 00:01:41,820 times five. 21 00:01:42,030 --> 00:01:43,890 It's repeating so many times. 22 00:01:43,890 --> 00:01:47,200 So I want to find out how many times is it being repeated. 23 00:01:47,400 --> 00:01:56,570 So I'm going to go in here and I'm going to say four and it's a strange city in cities array. 24 00:01:56,860 --> 00:01:57,660 Here's what they want to do. 25 00:01:57,660 --> 00:02:06,350 I want to say if City is equal to a string on this thing I'm looking for is Vancouver. 26 00:02:06,570 --> 00:02:09,110 If that's the case what should we do. 27 00:02:09,120 --> 00:02:11,570 We should actually start counting up. 28 00:02:11,610 --> 00:02:12,620 We should find a way. 29 00:02:12,630 --> 00:02:14,250 Oh I forgot the brackets here. 30 00:02:14,260 --> 00:02:15,930 So that was a method calling. 31 00:02:16,200 --> 00:02:19,110 So if it is like that we have to count it up. 32 00:02:19,110 --> 00:02:25,410 So I'm going to say at the very beginning there's an integer Ah let's call it divine call word count 33 00:02:25,410 --> 00:02:27,650 which is zero at the very beginning. 34 00:02:27,790 --> 00:02:35,460 And I'm going to say any time you find one that is Vancouver say Vancouver plus equal one. 35 00:02:35,590 --> 00:02:36,900 I want to it. 36 00:02:36,960 --> 00:02:44,050 So as it goes through the IRA if you find all occurrences add them to Vancouver around the end I'm going 37 00:02:44,050 --> 00:02:47,880 to say and like here is what's happening. 38 00:02:47,970 --> 00:02:57,400 Who were these repeat that the percentage of times on Halling times it has been repeated Vancourt counts 39 00:02:58,420 --> 00:03:00,530 for a semicolon at the end. 40 00:03:00,810 --> 00:03:08,870 So we go through our array every time the array object is Vancouver we count up and then Blancos repeat 41 00:03:09,150 --> 00:03:10,290 that many times. 42 00:03:10,410 --> 00:03:11,550 Let's run this code 43 00:03:18,110 --> 00:03:27,990 it is saying when it is repeated 14 times perfect so that they could simply try this for another city 44 00:03:28,040 --> 00:03:31,050 let's say Shanghai. 45 00:03:31,350 --> 00:03:40,660 I'm going to say Shanghai Shanghai is repeated Shanghai is only four times perfect. 46 00:03:40,690 --> 00:03:45,440 Or you could do other things with this something I would encourage you to do is I would encourage you 47 00:03:45,440 --> 00:03:53,600 to go through every name that is in here find the unique names put them in a list and then from there 48 00:03:53,600 --> 00:04:00,460 on go counting all of them and then find out which city is repeated more than others. 49 00:04:00,620 --> 00:04:10,200 So there you go assignments would be finding the most repeated or most repeated sitting. 50 00:04:10,280 --> 00:04:14,470 So that would be something that you could be doing and that would teach you a lot of things. 51 00:04:14,530 --> 00:04:19,250 I'm going to tell you what you should do you should go through all the elements of your array. 52 00:04:19,250 --> 00:04:24,180 One other time I them into a set because they cannot have duplicates. 53 00:04:24,200 --> 00:04:32,300 You end up having a set of unique names then for each object in the set you have to go 3 or eight count 54 00:04:32,300 --> 00:04:39,460 it up and add them into a dictionary that would for instance say for decie Vancouver the number is 14 55 00:04:39,460 --> 00:04:42,600 for the key Shang-Chi the number is four. 56 00:04:42,680 --> 00:04:44,050 So on and so forth. 57 00:04:44,150 --> 00:04:50,090 And at the end you have to go through all of the elements of your dictionary and find out which one 58 00:04:50,090 --> 00:04:51,920 is the highest number. 59 00:04:51,980 --> 00:04:57,440 It's got to be a bit of a difficult process if you're new to this but I think you will learn a lot from 60 00:04:57,440 --> 00:04:59,920 it if you manage to do it successfully. 61 00:05:00,080 --> 00:05:03,880 Please submit your code in the forum so others can benefit from it. 62 00:05:04,040 --> 00:05:09,460 And if you run into something that you really felt like you can fix it up just drop me a line. 63 00:05:09,470 --> 00:05:10,590 I hope help right. 64 00:05:10,940 --> 00:05:13,310 And with that let's move on to our next.