1 00:00:00,180 --> 00:00:07,650 Now we'll have a look at how the program conducts the next step of the examination that is calculating 2 00:00:07,650 --> 00:00:14,700 the factor of Space's, so recall that the next step of the examination involves finding the factors 3 00:00:14,700 --> 00:00:15,510 of this basis. 4 00:00:15,960 --> 00:00:19,590 We are looking for factors between two one, the Max Cleland indolent. 5 00:00:20,130 --> 00:00:26,220 To do this, we will create a function that is get useful factors, which is the next function, which 6 00:00:26,220 --> 00:00:32,860 takes no parameter and returns a list of only those factors that meet this criteria. 7 00:00:33,390 --> 00:00:35,430 So here we check for a special case. 8 00:00:35,430 --> 00:00:37,050 Vietnam is less than two. 9 00:00:37,590 --> 00:00:43,890 In this case, it returns the empty list because none would have no useful factors if it were less than 10 00:00:43,890 --> 00:00:46,760 two and a half numbers larger than two. 11 00:00:46,950 --> 00:00:51,170 It would need to calculate all the factors of number and store them in the list. 12 00:00:51,720 --> 00:00:54,650 So we create an empty list called as fact. 13 00:00:54,660 --> 00:01:02,190 Those over here OK to store the factors and the for loop loop through the individuals from to the Max 14 00:01:02,190 --> 00:01:05,850 Cleland plus one, including the value of the Max Ealand. 15 00:01:06,120 --> 00:01:11,430 Remember that because the range causes the four look to iterate up to, but not including the second 16 00:01:11,430 --> 00:01:11,940 argument. 17 00:01:12,240 --> 00:01:17,040 Hence we pass max length plus one so that even that is included. 18 00:01:17,040 --> 00:01:25,300 And this loop finds all the factors of NUW that after we have tested this with the number model I over 19 00:01:25,320 --> 00:01:32,880 here, if that is equal to zero and if it is, we know that I divide evenly with the remainder, which 20 00:01:32,880 --> 00:01:34,500 means I is a factor of no. 21 00:01:34,830 --> 00:01:40,140 So in this case, we append either the list of those in the fact those variable, because we know that 22 00:01:40,140 --> 00:01:43,590 number divided by I must also divide num evenly. 23 00:01:43,950 --> 00:01:48,550 So we store the integer form of it in the other factors that is over here. 24 00:01:49,410 --> 00:01:53,640 So if the resulting value is one, the program doesn't include it in the fact the list. 25 00:01:53,640 --> 00:01:56,150 So we check for this particular case also. 26 00:01:56,760 --> 00:02:03,930 And after this we are upending the value if it is not one, so we exclude one because Virginia has a 27 00:02:03,950 --> 00:02:04,770 length of one. 28 00:02:04,950 --> 00:02:08,010 The Virginia cipher would be no different than us is a cipher. 29 00:02:08,700 --> 00:02:13,240 With this, we move on to removing the duplicate with the set function. 30 00:02:13,590 --> 00:02:19,350 Now recall that we need to know the most common factor as part of the ASCII examination, because the 31 00:02:19,350 --> 00:02:23,760 most common factor will almost certainly be the length of the original. 32 00:02:24,120 --> 00:02:30,450 However, before we can analyze the frequency of each factor, we will need to use the set function 33 00:02:30,450 --> 00:02:33,340 to remove any duplicate factors from the list. 34 00:02:33,900 --> 00:02:40,470 For example, if they get useful factors, was past nine for no amateur, then nine modulo three equal 35 00:02:40,470 --> 00:02:41,640 to zero would be true. 36 00:02:41,640 --> 00:02:45,390 And both I and factor would have been appended to factors. 37 00:02:45,780 --> 00:02:52,440 But both I and in num divide by are equal to three, so three would be appended in the list twice. 38 00:02:52,830 --> 00:02:57,890 So to prevent duplicate numbers, we can pass the list to set which returns a list. 39 00:02:57,900 --> 00:03:04,860 As I said they got and they said that the type is similar to list the type except asset value can only 40 00:03:04,860 --> 00:03:06,090 contain unique value. 41 00:03:06,100 --> 00:03:12,540 So you can pass any list value to set function to get a set values that doesn't have any duplicate values 42 00:03:12,540 --> 00:03:12,840 in it. 43 00:03:13,410 --> 00:03:19,530 Conversely, if you pass a set value to a list, it would return the list value version to this of this. 44 00:03:19,530 --> 00:03:24,870 It not to see examples of this, we will have to enter certain things in the interactive shell. 45 00:03:25,140 --> 00:03:32,250 So let's go back to Interactive Shell here and we say sit in Blackett Square bracket seven, comma two 46 00:03:32,460 --> 00:03:35,370 three, one more three and then four. 47 00:03:36,270 --> 00:03:38,700 CLOUZOT So we get one, two, three, four. 48 00:03:38,700 --> 00:03:39,330 In this case. 49 00:03:39,570 --> 00:03:47,310 Similarly, if we c span is equal to the list, set open the bracket here. 50 00:03:47,310 --> 00:03:54,340 We pass Tacoma, Tacoma two, then all fixed, then again to come to close this. 51 00:03:54,630 --> 00:04:01,290 OK, and if we now Bridgespan we get only two, one gets so any repeated list values automatically remove 52 00:04:01,290 --> 00:04:02,450 removing the list is converted. 53 00:04:02,490 --> 00:04:07,260 Was it even when I it converted from a list is a reconverted to a list. 54 00:04:07,260 --> 00:04:09,690 It will still not have any repeated values. 55 00:04:10,140 --> 00:04:16,020 So coming back to our program here that is removing the duplicate factors and sorting the list over 56 00:04:16,020 --> 00:04:21,540 here, if you'll see, we are returning the list set in bracket factors, which removes the duplicate 57 00:04:21,540 --> 00:04:22,080 factors. 58 00:04:22,920 --> 00:04:28,140 So on this particular function, that is get item at index, which is the next function over here, 59 00:04:28,590 --> 00:04:34,500 it is almost identical to the get item at index zero, if which we have done in the frequency analysis 60 00:04:34,500 --> 00:04:34,970 program. 61 00:04:35,550 --> 00:04:40,860 Now, this function will be passed to start later in the program to solve based on the item at index, 62 00:04:40,860 --> 00:04:43,560 one of the items being sorted. 63 00:04:44,100 --> 00:04:47,370 So with this, we move on to finding the most common factors. 64 00:04:47,610 --> 00:04:53,040 So to find the most common factors, which are most likely the killens, we need to write down to get 65 00:04:53,040 --> 00:04:56,920 the most common factor, which is our next function here. 66 00:04:57,570 --> 00:04:59,220 Now, this sequence factor. 67 00:04:59,220 --> 00:04:59,730 Parameter. 68 00:04:59,930 --> 00:05:05,660 Takes a dictionary value created using the Kosofsky examination function, which will explain shortly. 69 00:05:05,990 --> 00:05:11,900 Now, this dictionary has a string of sequences as its keys and the list of individual factors as the 70 00:05:11,900 --> 00:05:13,310 value of each list. 71 00:05:13,880 --> 00:05:14,360 Now. 72 00:05:15,610 --> 00:05:17,980 We'll just put this like this. 73 00:05:18,580 --> 00:05:24,790 So now over here, this sequence factors we are talking about now, if we see, for example, the sequence 74 00:05:24,800 --> 00:05:30,130 factors could contain a dictionary value, which would look something like the VRA and having some numerical 75 00:05:30,130 --> 00:05:35,890 values, the ACLU having some numerical values and and having some numerical values. 76 00:05:36,100 --> 00:05:42,370 Now, this gets to most common factors or those the most common factors in the sequence factors from 77 00:05:42,370 --> 00:05:49,180 the most frequently, according to the least according and returns them as a list of 20 Georgopoulos 78 00:05:49,480 --> 00:05:52,630 first integer, which is a tuple is a factor. 79 00:05:52,960 --> 00:05:57,000 And the second integer is how many times it appeared in the sequence factor. 80 00:05:57,640 --> 00:06:02,290 Now, for example, again, the most common factor might return the value, something like the three 81 00:06:02,590 --> 00:06:06,390 five five six six six five twenty nine, something like that. 82 00:06:06,610 --> 00:06:11,950 So this particular thing would be something like factor three, four, five, five, six times. 83 00:06:12,160 --> 00:06:16,460 Also a factor six to five, twenty nine times, so on and so forth. 84 00:06:16,840 --> 00:06:22,750 So the fourth step in the most common factors, we will set up the factor count lectionary, which we 85 00:06:22,750 --> 00:06:24,880 will use to store the count of each factor. 86 00:06:24,880 --> 00:06:31,690 And the key factor counts will be the factor and the value associated with the keys will the count of 87 00:06:31,690 --> 00:06:32,800 those factors. 88 00:06:33,010 --> 00:06:40,150 Now, next in this, we have a for loop given which loops over every sequence in the sequence factors, 89 00:06:40,930 --> 00:06:47,200 storing it in a variable name askew on each side and the list of factors in the sequence factors for 90 00:06:47,310 --> 00:06:50,110 a stored in the variable named factor list. 91 00:06:50,740 --> 00:06:57,130 Now the factor in this list are looped over with another for loop, and if the factor doesn't exist 92 00:06:57,130 --> 00:07:04,120 as a key factor count, it's added on to the next one with a value on it of zero, which is over here. 93 00:07:04,990 --> 00:07:10,710 Then the incremental factor account factor by one, which is the factors, value and effect account. 94 00:07:11,500 --> 00:07:15,010 Now for the second step of the get most common factors function. 95 00:07:15,250 --> 00:07:19,000 We need to sort the values in the factor, contradictory by the count. 96 00:07:19,330 --> 00:07:25,450 But because dictionary values aren't order, we must first convert a dictionary to a list of two integer 97 00:07:25,450 --> 00:07:28,620 tuples, something like we are doing over here. 98 00:07:28,630 --> 00:07:32,770 So we are sorting the list of values in a variable named factors by count here. 99 00:07:33,160 --> 00:07:40,900 And then we loop through the each of the factors into account and append this particular factor, comma 100 00:07:41,020 --> 00:07:47,200 factor count at the index of factor, apply to the factors by count list only if in fact that is less 101 00:07:47,200 --> 00:07:49,570 than or equal to the max length. 102 00:07:49,840 --> 00:07:53,440 And after this finishes adding all the tuples, three factors. 103 00:07:53,440 --> 00:07:59,980 By count, we started using this method as the final step of our get most common factors. 104 00:08:00,170 --> 00:08:07,490 And finally, here we return factors by count now because the get item at index one function as passed 105 00:08:07,510 --> 00:08:12,070 for the key keyword argument and two is parsed for the reversible argument. 106 00:08:12,400 --> 00:08:18,760 The list is sorted by factor in descending order and returns the sorted list in the factors that count, 107 00:08:18,760 --> 00:08:25,330 which should indicate which factors are most frequently and therefore are most likely to be the beginning 108 00:08:25,330 --> 00:08:26,130 of Gilan. 109 00:08:26,980 --> 00:08:28,130 That set from the session. 110 00:08:28,150 --> 00:08:29,020 Thank you very much.