Now we'll have a look at how the program conducts the next step of the examination that is calculating
the factor of Space's, so recall that the next step of the examination involves finding the factors
of this basis.
We are looking for factors between two one, the Max Cleland indolent.
To do this, we will create a function that is get useful factors, which is the next function, which
takes no parameter and returns a list of only those factors that meet this criteria.
So here we check for a special case.
Vietnam is less than two.
In this case, it returns the empty list because none would have no useful factors if it were less than
two and a half numbers larger than two.
It would need to calculate all the factors of number and store them in the list.
So we create an empty list called as fact.
Those over here OK to store the factors and the for loop loop through the individuals from to the Max
Cleland plus one, including the value of the Max Ealand.
Remember that because the range causes the four look to iterate up to, but not including the second
argument.
Hence we pass max length plus one so that even that is included.
And this loop finds all the factors of NUW that after we have tested this with the number model I over
here, if that is equal to zero and if it is, we know that I divide evenly with the remainder, which
means I is a factor of no.
So in this case, we append either the list of those in the fact those variable, because we know that
number divided by I must also divide num evenly.
So we store the integer form of it in the other factors that is over here.
So if the resulting value is one, the program doesn't include it in the fact the list.
So we check for this particular case also.
And after this we are upending the value if it is not one, so we exclude one because Virginia has a
length of one.
The Virginia cipher would be no different than us is a cipher.
With this, we move on to removing the duplicate with the set function.
Now recall that we need to know the most common factor as part of the ASCII examination, because the
most common factor will almost certainly be the length of the original.
However, before we can analyze the frequency of each factor, we will need to use the set function
to remove any duplicate factors from the list.
For example, if they get useful factors, was past nine for no amateur, then nine modulo three equal
to zero would be true.
And both I and factor would have been appended to factors.
But both I and in num divide by are equal to three, so three would be appended in the list twice.
So to prevent duplicate numbers, we can pass the list to set which returns a list.
As I said they got and they said that the type is similar to list the type except asset value can only
contain unique value.
So you can pass any list value to set function to get a set values that doesn't have any duplicate values
in it.
Conversely, if you pass a set value to a list, it would return the list value version to this of this.
It not to see examples of this, we will have to enter certain things in the interactive shell.
So let's go back to Interactive Shell here and we say sit in Blackett Square bracket seven, comma two
three, one more three and then four.
CLOUZOT So we get one, two, three, four.
In this case.
Similarly, if we c span is equal to the list, set open the bracket here.
We pass Tacoma, Tacoma two, then all fixed, then again to come to close this.
OK, and if we now Bridgespan we get only two, one gets so any repeated list values automatically remove
removing the list is converted.
Was it even when I it converted from a list is a reconverted to a list.
It will still not have any repeated values.
So coming back to our program here that is removing the duplicate factors and sorting the list over
here, if you'll see, we are returning the list set in bracket factors, which removes the duplicate
factors.
So on this particular function, that is get item at index, which is the next function over here,
it is almost identical to the get item at index zero, if which we have done in the frequency analysis
program.
Now, this function will be passed to start later in the program to solve based on the item at index,
one of the items being sorted.
So with this, we move on to finding the most common factors.
So to find the most common factors, which are most likely the killens, we need to write down to get
the most common factor, which is our next function here.
Now, this sequence factor.
Parameter.
Takes a dictionary value created using the Kosofsky examination function, which will explain shortly.
Now, this dictionary has a string of sequences as its keys and the list of individual factors as the
value of each list.
Now.
We'll just put this like this.
So now over here, this sequence factors we are talking about now, if we see, for example, the sequence
factors could contain a dictionary value, which would look something like the VRA and having some numerical
values, the ACLU having some numerical values and and having some numerical values.
Now, this gets to most common factors or those the most common factors in the sequence factors from
the most frequently, according to the least according and returns them as a list of 20 Georgopoulos
first integer, which is a tuple is a factor.
And the second integer is how many times it appeared in the sequence factor.
Now, for example, again, the most common factor might return the value, something like the three
five five six six six five twenty nine, something like that.
So this particular thing would be something like factor three, four, five, five, six times.
Also a factor six to five, twenty nine times, so on and so forth.
So the fourth step in the most common factors, we will set up the factor count lectionary, which we
will use to store the count of each factor.
And the key factor counts will be the factor and the value associated with the keys will the count of
those factors.
Now, next in this, we have a for loop given which loops over every sequence in the sequence factors,
storing it in a variable name askew on each side and the list of factors in the sequence factors for
a stored in the variable named factor list.
Now the factor in this list are looped over with another for loop, and if the factor doesn't exist
as a key factor count, it's added on to the next one with a value on it of zero, which is over here.
Then the incremental factor account factor by one, which is the factors, value and effect account.
Now for the second step of the get most common factors function.
We need to sort the values in the factor, contradictory by the count.
But because dictionary values aren't order, we must first convert a dictionary to a list of two integer
tuples, something like we are doing over here.
So we are sorting the list of values in a variable named factors by count here.
And then we loop through the each of the factors into account and append this particular factor, comma
factor count at the index of factor, apply to the factors by count list only if in fact that is less
than or equal to the max length.
And after this finishes adding all the tuples, three factors.
By count, we started using this method as the final step of our get most common factors.
And finally, here we return factors by count now because the get item at index one function as passed
for the key keyword argument and two is parsed for the reversible argument.
The list is sorted by factor in descending order and returns the sorted list in the factors that count,
which should indicate which factors are most frequently and therefore are most likely to be the beginning
of Gilan.
That set from the session.
Thank you very much.