1 00:00:00,530 --> 00:00:03,720 So now let's see, implementing the dictionary file. 2 00:00:04,100 --> 00:00:08,880 Let us return to our English Dot Birame and set up the dictionary file here. 3 00:00:09,200 --> 00:00:15,230 Now the dictionary defines search on the user's hard drive, but unless we load the text in this file 4 00:00:15,230 --> 00:00:18,430 as a string value of a python code, can't use it. 5 00:00:18,540 --> 00:00:18,860 OK. 6 00:00:19,980 --> 00:00:25,440 Hence, we have created this lord, the helper function to do this. 7 00:00:25,770 --> 00:00:28,170 OK, so here we are seeing the dictionary file. 8 00:00:28,170 --> 00:00:31,740 SDR is equal to open in this in quotation marks. 9 00:00:31,750 --> 00:00:32,830 We have given dictionary. 10 00:00:34,110 --> 00:00:38,080 Then we have created English words, SDR as a blank dictionary. 11 00:00:38,400 --> 00:00:43,680 So first we get the dictionary file object by calling the open method and passing the string of the 12 00:00:44,010 --> 00:00:45,750 filename dictionary, not the. 13 00:00:46,560 --> 00:00:52,680 Then we named the dictionary variable English word is the answer to to an empty dictionary initially 14 00:00:53,190 --> 00:00:56,820 now will store all the votes in the dictionary file. 15 00:00:57,240 --> 00:01:00,510 That is a file that stored the English dictionary value. 16 00:01:00,510 --> 00:01:06,870 The Python data or the similar names are unfortunate, but the two are completely different. 17 00:01:07,170 --> 00:01:09,720 So dictionary still is different than English. 18 00:01:09,780 --> 00:01:12,480 Orestiada is totally different right now. 19 00:01:12,480 --> 00:01:18,420 Even though we would have used a list to store the string values of each word in the dictionary file, 20 00:01:18,420 --> 00:01:24,870 we are using a dictionary instead because the interpreter volks faster on dictionaries, then normal 21 00:01:24,900 --> 00:01:25,290 list. 22 00:01:25,800 --> 00:01:32,460 OK, now next we will learn about the split string method which will be used in our OR to split our 23 00:01:32,460 --> 00:01:34,370 dictionary file into substring. 24 00:01:34,740 --> 00:01:37,200 So let us understand the split matter first. 25 00:01:37,470 --> 00:01:44,310 Now the split string method takes one string and returns a list of several strings by splitting the 26 00:01:44,310 --> 00:01:46,620 past string at each space. 27 00:01:47,040 --> 00:01:48,870 Now gives you an example for this. 28 00:01:49,140 --> 00:01:54,540 We will go forward to the interactive shell and try to split some votes and get the output. 29 00:01:55,790 --> 00:02:01,250 So let's go back to interactive shall here and we will type see. 30 00:02:02,030 --> 00:02:19,090 This is python hacking, intermediate level goes OK and dot and then we use a split method of it, OK? 31 00:02:19,250 --> 00:02:22,760 Now it has at every word after the space. 32 00:02:23,160 --> 00:02:23,570 Right. 33 00:02:23,720 --> 00:02:27,220 So this is the oldest of a string that we have got here. 34 00:02:27,830 --> 00:02:34,670 Now it is one string for each of the wall in the original string spaces are dropped from the items in 35 00:02:34,670 --> 00:02:37,700 the list, even if there is more than one space. 36 00:02:37,700 --> 00:02:44,630 If you have given, you can just pass an optional argument or split to split it on a different string 37 00:02:44,840 --> 00:02:46,280 other than a space. 38 00:02:46,680 --> 00:02:53,240 OK, now, for example, if we try to enter something like, say, this is or this, then we separate 39 00:02:53,240 --> 00:03:05,660 it with A is C Biton hacking intermediate level course. 40 00:03:06,330 --> 00:03:13,230 OK, and again, here we see split, but this time we give eight in the bracket. 41 00:03:13,580 --> 00:03:17,570 So now with the splitting, wherever it is finding it, that is a separate word for it. 42 00:03:18,140 --> 00:03:22,550 OK, this is how we have used this for another way in which you can split it. 43 00:03:22,970 --> 00:03:29,320 So notice that the string doesn't have any spaces on this using a split and passing double it split 44 00:03:29,330 --> 00:03:36,290 the original string wherever it occurs, resulting in the list of again, seven different part of the 45 00:03:36,290 --> 00:03:36,810 string. 46 00:03:37,220 --> 00:03:41,750 OK, now using the splitting the dictionary file into individual words. 47 00:03:42,140 --> 00:03:48,860 So let us return to our code that we have created here, OK, and where we have used the split function 48 00:03:48,860 --> 00:03:55,550 here for everyone in the dictionary file Estado three dot split on a new line. 49 00:03:55,670 --> 00:03:58,310 OK, so let's break down the particular code. 50 00:03:58,640 --> 00:04:03,620 The dictionary file is still variable that stored the file object of the open file. 51 00:04:04,040 --> 00:04:10,700 We are using that really matter which calls, read the entire file and returns it as a large string 52 00:04:10,700 --> 00:04:11,110 value. 53 00:04:11,570 --> 00:04:17,630 We then call the split method on this long string and split it on a new line character because dictionary 54 00:04:17,630 --> 00:04:20,750 file that we have has one word borderline. 55 00:04:21,080 --> 00:04:26,660 So splitting on a new line character returns a list of values made up of each word in the dictionary. 56 00:04:26,690 --> 00:04:33,270 Right now they use a for loop at the beginning of the line, which I tripped over each word of the store, 57 00:04:33,380 --> 00:04:40,270 one each in a key, but don't need values associated with the key since we are using dictionary database. 58 00:04:40,580 --> 00:04:43,430 So we'll just store the non-value for each. 59 00:04:44,610 --> 00:04:48,880 Hence, we have stories non-value for every key now. 60 00:04:48,900 --> 00:04:55,290 None is a type of value that you can assign to a variable to represent the lack of a value, whereas 61 00:04:55,500 --> 00:04:57,780 the boolean data depends on little values. 62 00:04:58,020 --> 00:05:00,300 None type has only one value, that is. 63 00:05:00,840 --> 00:05:05,520 It's always returned without goods and with a capital end like we have written here. 64 00:05:05,880 --> 00:05:12,060 OK, so for example, you say you had a variable named C answer which holds a user answer to a true 65 00:05:12,060 --> 00:05:13,910 or false pop quiz question. 66 00:05:14,160 --> 00:05:19,930 And if the user skips a question and doesn't answer it, it makes the most sense to assign the answer 67 00:05:19,950 --> 00:05:23,280 variable to none as a default value rather than true or false. 68 00:05:23,630 --> 00:05:28,860 Otherwise, it might look like the user answered the question when they did so. 69 00:05:28,860 --> 00:05:33,840 Likewise, we have the function calls that exist by reaching the end of the function and not from the 70 00:05:33,840 --> 00:05:37,900 return statement which evaluate to null because they don't return anything. 71 00:05:38,310 --> 00:05:44,550 OK, so over here, the word that is being traded over Azuki in the English word restaurant stoltmann 72 00:05:44,580 --> 00:05:46,320 as a value for that particular key. 73 00:05:46,590 --> 00:05:54,540 We have gone inside for loop now coming to returning the dictionary better now after default finishes 74 00:05:54,780 --> 00:06:01,020 the English word astar dictionary should have different types of or whatever votes you are having as 75 00:06:01,020 --> 00:06:02,130 the key in it. 76 00:06:02,170 --> 00:06:08,310 OK, so at this point we close the file object by saying dictionary file is still not close because 77 00:06:08,310 --> 00:06:14,080 we are done reading it and then return the value of the English word SDR from the function. 78 00:06:14,490 --> 00:06:19,980 OK, we then call basically our Lord and store the dictionary value. 79 00:06:20,110 --> 00:06:26,180 It returns in a variable that is named English Word Asgeir, which is also a constant. 80 00:06:26,580 --> 00:06:31,950 So we want to call the Lord before the rest of the code in the English module. 81 00:06:31,950 --> 00:06:36,980 But Python must execute the statement for Lord the Rockets. 82 00:06:37,050 --> 00:06:38,470 So before we call the function. 83 00:06:38,700 --> 00:06:41,730 This is the reason we have assignment for the word English. 84 00:06:41,730 --> 00:06:48,120 Forestier comes after the law dictionary function has been written the first we have defined the function 85 00:06:48,120 --> 00:06:52,410 and then we are storing that value of the function in the given constant. 86 00:06:52,920 --> 00:06:58,590 Now let's move on to counting the number of English words in the message so we go ahead with the next 87 00:06:58,590 --> 00:06:59,220 definition. 88 00:06:59,220 --> 00:07:02,170 That is get English word, count, method, definition. 89 00:07:03,000 --> 00:07:08,400 So here we have written the program code that defines the good English count, but English word count 90 00:07:08,400 --> 00:07:16,020 function, which takes a string argument and returns a flow to value, indicating the ratio of recognized 91 00:07:16,020 --> 00:07:22,110 English words to total of the votes now will represent the racialize of value between zero point zero 92 00:07:22,110 --> 00:07:23,130 and one point zero. 93 00:07:23,850 --> 00:07:29,910 Now, nowhere a value of zero point zero means none of the words in English or in the message string 94 00:07:29,910 --> 00:07:35,520 are English words, and 1.0 means all of the words in the past parameter are English words. 95 00:07:35,760 --> 00:07:41,370 So most likely to get the English word count will return of value between zero point zero and one point 96 00:07:41,370 --> 00:07:41,730 zero. 97 00:07:42,030 --> 00:07:49,410 And the IS English function uses this return value to determine whether to evaluate it as true or false. 98 00:07:49,870 --> 00:07:55,160 OK, so when we use this, we created, as I suggested, is equal to start up. 99 00:07:55,650 --> 00:08:00,560 Then we have removed the noun letters which we have created below and then possible. 100 00:08:00,570 --> 00:08:01,200 What a start. 101 00:08:01,200 --> 00:08:02,100 We get messages. 102 00:08:02,110 --> 00:08:03,270 Gardot split.