1
00:00:02,130 --> 00:00:04,620
This video, we will build an English dictionary.

2
00:00:04,830 --> 00:00:10,620
This is a program which gets from the user a word in English and in three turns the definition of that

3
00:00:10,620 --> 00:00:11,880
word in English.

4
00:00:12,240 --> 00:00:15,330
Now we will be using Jason -.So for this.

5
00:00:15,750 --> 00:00:20,160
So Jason, he said, other formats and it's similar to a Python dictionary.

6
00:00:20,400 --> 00:00:26,670
So in this video, you learn how to pass that these data and extract information from those data.

7
00:00:28,050 --> 00:00:33,780
So the idea is that the data said the dictionary itself is stored in these JSON delta and this is a

8
00:00:33,780 --> 00:00:34,110
file.

9
00:00:34,110 --> 00:00:37,260
You can find this at the end of the lecture resources.

10
00:00:38,280 --> 00:00:42,500
So you need to place it in your project directory and they look like this.

11
00:00:42,510 --> 00:00:44,760
Be careful not to change anything here.

12
00:00:45,270 --> 00:00:50,220
Otherwise, the format may be corrupted and Python will not recognize that.

13
00:00:50,580 --> 00:00:52,410
So you will get some errors later.

14
00:00:53,310 --> 00:01:00,720
What we have here is a big dictionary, and this dictionary is made of keys and values.

15
00:01:01,680 --> 00:01:10,980
So that's the value of the first key of the other pair key and value up to here.

16
00:01:12,240 --> 00:01:14,060
So the key is a word.

17
00:01:14,070 --> 00:01:20,100
The value is a list which may contain one or more definitions for that two words.

18
00:01:21,180 --> 00:01:22,470
So these are adjacent.

19
00:01:22,810 --> 00:01:24,960
And as I say, that these are similar to Python.

20
00:01:25,200 --> 00:01:32,940
Now let's go to Python painful JSON, which is a Python standard library to parse Jason data.

21
00:01:33,570 --> 00:01:42,180
And then the next thing we should do is apply that JSON that loads method and the load method expects

22
00:01:43,020 --> 00:01:53,930
a file object as inputs so we can create a file object in here file equal to open data.

23
00:01:54,080 --> 00:02:01,230
Jason So that will create a file in read mode and we provide that file in here.

24
00:02:01,710 --> 00:02:03,690
And if you print that up.

25
00:02:07,570 --> 00:02:11,680
You're going to get all those that are printed out in your terminal.

26
00:02:12,490 --> 00:02:15,040
So it's the same delta as we saw in here.

27
00:02:16,180 --> 00:02:19,000
And it is a Python dictionary.

28
00:02:19,360 --> 00:02:26,650
So if you print out the type stop print, you're going to see class DeCoutere.

29
00:02:27,520 --> 00:02:36,520
That means you can now access any of the keys, such as islands.

30
00:02:40,110 --> 00:02:43,740
So if you access the key islands, you get a list.

31
00:02:44,250 --> 00:02:49,140
So this list happens to have one and two items.

32
00:02:49,770 --> 00:02:52,260
So there are two definitions for the word islands.

33
00:02:54,270 --> 00:02:58,950
So I would like to make this more robust and create a function.

34
00:03:02,200 --> 00:03:15,040
So define, define this will get a word as input if the words in Delta eight to the return.

35
00:03:17,470 --> 00:03:19,480
The definition of that word, sorry.

36
00:03:20,020 --> 00:03:21,340
Words as a variable.

37
00:03:23,080 --> 00:03:32,440
So that our words will be like Delta Island, for example, Delta Sun, etc. So this will happen if

38
00:03:32,980 --> 00:03:41,590
the world is in that dictionary, otherwise else we want to return none.

39
00:03:43,060 --> 00:03:45,670
But are you going to amidst this expression?

40
00:03:45,670 --> 00:03:52,660
Because if the if condition is not ever alluded to by default, this function will return none.

41
00:03:53,640 --> 00:03:56,430
So there is no need to return, not explicitly.

42
00:03:57,840 --> 00:04:04,680
So, no, we can see we can get the words from the user base into a word

43
00:04:07,590 --> 00:04:10,470
and then we get the definition from the defined function.

44
00:04:10,650 --> 00:04:11,800
But passing that word?

45
00:04:12,270 --> 00:04:16,589
So word goes in here as an input.

46
00:04:18,850 --> 00:04:27,790
To the function, call and print out the definition, and so, yeah, that looks fine.

47
00:04:28,240 --> 00:04:30,670
I'll remove this print statement up here.

48
00:04:31,090 --> 00:04:33,730
Remove that and run.

49
00:04:35,630 --> 00:04:40,550
So police enter a woods island and we get this list.

50
00:04:41,270 --> 00:04:45,680
What if we put a word which doesn't exist?

51
00:04:47,220 --> 00:04:53,010
Such as Iceland with the set, so we get none.

52
00:04:53,430 --> 00:05:02,220
If you want to improve this article, you could simply do here if definition print.

53
00:05:04,860 --> 00:05:07,090
Definition else.

54
00:05:07,640 --> 00:05:13,140
Brent Woods was not fond and run.

55
00:05:15,810 --> 00:05:21,800
And the word ises and word was not found is written as.

56
00:05:24,410 --> 00:05:30,680
Another improvement of life to make here is that, you know, if you answer the correct words such as

57
00:05:30,680 --> 00:05:33,890
Ireland boss, you enter a capital I.

58
00:05:34,880 --> 00:05:37,010
And you press, enter this race.

59
00:05:37,200 --> 00:05:42,530
And it was not fun because Ireland's here is in lowercase letters.

60
00:05:42,890 --> 00:05:49,430
So Ireland with a capital I and Ireland with a low case, I are not the same.

61
00:05:50,390 --> 00:05:52,400
So you want to change that.

62
00:05:52,910 --> 00:06:02,050
You want to see if world is lower, so you get the words of the user and you convert it into lowercase.

63
00:06:02,060 --> 00:06:07,190
So what you check in the delta is the lowercase version of that's user input.

64
00:06:08,180 --> 00:06:18,800
So if you were on that answer, I along with uppercase, I enter, Oh, we got an error in line eight.

65
00:06:19,040 --> 00:06:22,180
Obviously, we need to cover that in here, too.

66
00:06:22,370 --> 00:06:29,380
So instead of doing that, just say words is equal to words, not lower.

67
00:06:29,930 --> 00:06:36,860
So this variable now is converted into a lowercase for all the occurrences of the words variable inside

68
00:06:36,860 --> 00:06:37,460
this function.

69
00:06:37,850 --> 00:06:42,620
So run that again, try again, islands.

70
00:06:42,620 --> 00:06:46,130
And this time we get this list of definitions.

71
00:06:46,820 --> 00:06:51,530
Would you like to improve the ultimate even further by removing this brackets?

72
00:06:51,950 --> 00:06:58,760
Well, for that, instead of printing either definition, which is a list you want to iterate and see

73
00:06:58,760 --> 00:07:01,830
the list for item in definition.

74
00:07:02,360 --> 00:07:03,560
So definition is the least.

75
00:07:03,560 --> 00:07:08,510
We trade over the items and we print out each item in here run.

76
00:07:11,640 --> 00:07:19,170
And so now we have no brackets, so every line is printed out as an individual sentence.

77
00:07:19,800 --> 00:07:21,300
And that's concludes this video.

78
00:07:21,330 --> 00:07:21,900
Thank you.

79
00:07:21,930 --> 00:07:22,650
I'll see you later.

