So overcoming Jane this listening is actually a quick exercise.
And along with this lesson I have provided you with an array which includes the names of so many many
different cities and within those there is are several copies of the name Vancouver.
So they want you to do is I want you to write a program that can find out how many copies of Vancouver
are within the array.
So post the video now try on your own.
Try to iterate through all the elements of the array and count the number of occurrences of Vancouver
and print at the end and then once you are done you can you know playback the video again and find out
if your solution is right or if you are the better solution or if there are things that we don't quite
manage to complete.
So let's pause the video now and then continue.
So here's how I'm going to do it.
Let's jump back into ex-cult
I'm going to start in your project I'm going to call Ed Curran says exercise.
If that's how you spell occurrence I hope so.
I'm also going to go with that and clean things up as usual to get a better formatting by dot.
I'm also going to the file that you have received with this lesson and get a copy of that.
So that's a copy and paste it here.
So I have an array with so many many different cities around the Vancouver once twice three times four
times five.
It's repeating so many times.
So I want to find out how many times is it being repeated.
So I'm going to go in here and I'm going to say four and it's a strange city in cities array.
Here's what they want to do.
I want to say if City is equal to a string on this thing I'm looking for is Vancouver.
If that's the case what should we do.
We should actually start counting up.
We should find a way.
Oh I forgot the brackets here.
So that was a method calling.
So if it is like that we have to count it up.
So I'm going to say at the very beginning there's an integer Ah let's call it divine call word count
which is zero at the very beginning.
And I'm going to say any time you find one that is Vancouver say Vancouver plus equal one.
I want to it.
So as it goes through the IRA if you find all occurrences add them to Vancouver around the end I'm going
to say and like here is what's happening.
Who were these repeat that the percentage of times on Halling times it has been repeated Vancourt counts
for a semicolon at the end.
So we go through our array every time the array object is Vancouver we count up and then Blancos repeat
that many times.
Let's run this code
it is saying when it is repeated 14 times perfect so that they could simply try this for another city
let's say Shanghai.
I'm going to say Shanghai Shanghai is repeated Shanghai is only four times perfect.
Or you could do other things with this something I would encourage you to do is I would encourage you
to go through every name that is in here find the unique names put them in a list and then from there
on go counting all of them and then find out which city is repeated more than others.
So there you go assignments would be finding the most repeated or most repeated sitting.
So that would be something that you could be doing and that would teach you a lot of things.
I'm going to tell you what you should do you should go through all the elements of your array.
One other time I them into a set because they cannot have duplicates.
You end up having a set of unique names then for each object in the set you have to go 3 or eight count
it up and add them into a dictionary that would for instance say for decie Vancouver the number is 14
for the key Shang-Chi the number is four.
So on and so forth.
And at the end you have to go through all of the elements of your dictionary and find out which one
is the highest number.
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
it if you manage to do it successfully.
Please submit your code in the forum so others can benefit from it.
And if you run into something that you really felt like you can fix it up just drop me a line.
I hope help right.
And with that let's move on to our next.