So the Getler function, which we have defined here, is basically text messages, string and returns
a dictionary value whose keys are a single uppercase letter strings and whose values are in BIJA that
stores the number of times that letter goes in the message parameter.
So here we have created a letter found SDR variable by assigning it to a dictionary that has all said
Stewart, initial value of zero.
Hence we have set all the keys from A to Z.
Everything's A to Z.
OK, we then increment the value associated with the key until they represent the count of each letter
by taking each character in the message using a form Lupul.
So we have before this year in the message dot Apple.
If your letter Asgeir is in the constant then you make or incremental value.
So therefore loop iterate through each character in the uppercase version of the message SDR and assigns
the character to the letter OCR variable.
Then we check whether the character exists in the constant letters string because we don't want to count
the known little characters in the messages.
So when the letter is a part of your constant increments, the value at letter count are the index of
letters plus is equal to one.
So after the for loop, the letter count is your dictionary should have a count showing how often each
letter appeared in the messages and the dictionary is written from the get a letter count as saying
return the letter count as dear.
OK, now if we move on to the next one, say getting the first member of the stupid now the get item
at the index zero function returns the items at index zero when the duopolies pass to it.
So it is just having a simple written statement given.
And later in this session we will pass this function to this sort method to sort the frequency of the
letters into numerical order.
OK, we will look at this in detail in the some other sections of hacking.
But as of now, currently, we will be using this function to sort.
So moving to the ordering the letters in the message by frequency.
The next function that we have defined is our get frequency order function, which takes a message string
as an argument and returns a string with a twenty six uppercase letters of alphabet arranged by how
frequently the upbuilding message parameter f message is readable English instead of random anything.
It's likely that the string will be similar, if not identical to the string in the edit or in constant.
The code in the frequency or the function does most of the work of calculating the string frequency
score, which we will be using in order which will be used in the Virginia hacking program in the next
session.
OK, for example, if we have passed certain string to it, the function would return the string in
a particular order because E is the most common letter which would be used, for example, followed
by B then I then and then so on.
So the frequency of the function consists of five steps.
First, if you are counting the letters in the string, second is creating a dictionary of frequency
columns and the letter list is sorting the letters list in the rebels or in order for this converting
this data to the list of tuples.
And the last is converting the list into the final string to return from the function, get frequency
or the function.
Now let us look at each of these step into succumbing to the first one that is found in the letters
with the little count function.
OK, so over here before step off your get frequency auto function, which calls together that account
function with the message parameter to get the dictionary named letter frequency is containing count
of every letter in the message.
OK, so after this two lines of code that we have written, we get the values there and then we pass
this particular string as the parameter.
For example, say we have passed by and hacking something like that or Alan Matheson.
Now this particular string would be then assigned to the letter to frequency function and then we will
get how much it is being used or how frequently it is being used.
OK, then next we have is creating a dictionary of frequently counts and the letter list.
So the second step in this is all this function is to create a dictionary.
That is the frequency to let Oresteia, whose keys are the frequency count and whose values are the
list of letters with those frequency counts, whereas the letter to frequency ACR, which is a.
Redmap Lecoq used to frequency values the frequency to let Orestiada, which we have that Maxey frequency
keys to the list of the letter values, so we will need to flip the key and the values in later to frequency
dictionary will flip the keys and values because the multiple letters would have the same frequency
count be N.W..
Both would have a frequency count, for example, Silvani to put them in a dictionary, said 30 Colombe.
And because the order dictionary key must be unique, otherwise dictionary values will look like something
like 30 Colombe another 30 colon w which is wrong, which will simply overwrite one of these key value
pair with another.
So to make the frequency to little dictionary, we have created a blank dictionary first over here.
That is your frequency to letter estab.
Then we have a for loop saying four letters are in your constant letters this year.
If the frequency is still at the index letter is not in your frequency to let Oresteia then we are saying
frequency two letter instead of the index of letter to frequency.
Asgeir letter instead is equal to last year is we are saying frequency two letters are the index of
negative frequency StarTalk upending the value of letters.
So in this particular loop we are looping over all the letters and letters and then the if statement
checks whether the letter frequencies or the frequency are already exist as a the frequency two letters.
If not, then it adds this.
Give the list of letters as the value.
And if the letters frequency already exist and the key in the frequency to letters, it simply updates
the letter to the end of the list.
Already in the letter to frequency and stamp.
Now using the example value of the letter, the frequency are created using some particular string.
The frequency two letters should now return something which will have like although we had everything
to zero, but now we will have a control, key value.
But now if we move on to the next thing that this sorting the letter list in reverse order.
Now the third step in this get frequency involves sorting the letter strings in each list of frequency.
Two letters, dear.
So we recall that the frequency two letters are evaluates to a list of letters that has a frequency
count of frequency.
We will use a list because it's possible for two or more letters to have the same frequency count,
in which case it would list would have strings made up of two or more letters.
So when multiple letters have the same frequency commas, we want to sort that letters in the reverse
order compared to the order in which they appear in the old string.