1
00:00:03,270 --> 00:00:08,380
Good! As I mentioned previously in the
previous video now we need to take into

2
00:00:08,380 --> 00:00:14,530
consideration whether the user mistyped
something so instead of rain they

3
00:00:14,530 --> 00:00:20,800
entered an extra N there or something
like that and in that case you want to

4
00:00:20,800 --> 00:00:28,089
let the user now that they typed something
wrong there. So how do we do that? Well if

5
00:00:28,089 --> 00:00:33,640
you have no idea how to do that
the best practice is to actually do some

6
00:00:33,640 --> 00:00:38,440
research on Google because you know the
world of programming is very wide and

7
00:00:38,440 --> 00:00:44,500
you don't necessarily need to know every
possible workaround or solution to do

8
00:00:44,500 --> 00:00:51,579
something. So basically we need to figure
out an algorithm to compare let's say

9
00:00:51,579 --> 00:00:58,510
the word rain with NN and the word, the
actual word rain with one N at the

10
00:00:58,510 --> 00:01:03,360
end, and say that whether these are,
decide whether these are similar or not.

11
00:01:03,360 --> 00:01:09,520
But you don't have to reinvent the wheel
if someone else has done it already, so

12
00:01:09,520 --> 00:01:14,680
that's why you need to do some research
on the web and see if this says something

13
00:01:14,680 --> 00:01:21,490
that, if there is a library that exists
there or someone has a source code that does

14
00:01:21,490 --> 00:01:26,320
it, a function, or something like that.
But usually, often you find a library

15
00:01:26,320 --> 00:01:33,310
for that. So if you do a research for that, you
realize that you can do that using a few

16
00:01:33,310 --> 00:01:38,950
libraries and one of them is a standard
library and it's called DiffLib. By the

17
00:01:38,950 --> 00:01:45,759
way you can get a list of standard, of
Python standard libraries in this

18
00:01:45,759 --> 00:01:53,200
page so Python.org library index
dot HTML. This is the link. Here are all the

19
00:01:53,200 --> 00:01:58,979
standard libraries that you can import
into Python.

20
00:01:59,000 --> 00:02:08,369
So let me go here and import difflib
So this is a library to compare text

21
00:02:08,369 --> 00:02:14,580
and one of the methods is sequence
matcher. It's a long name so what can we

22
00:02:14,580 --> 00:02:26,599
say is from difflib import sequence
matcher. What that does is� SequenceMatcher.

23
00:02:26,599 --> 00:02:33,600
You need to pass None there. None is the
value for the argument isjunk, so the

24
00:02:33,600 --> 00:02:38,459
first argument is an argument called
isjunk which means that, you know if you're

25
00:02:38,459 --> 00:02:43,319
comparing two blocks of text,
in this case we're just comparing words,

26
00:02:43,319 --> 00:02:48,239
so if you comparing two blocks of text
and you have some junk there you have

27
00:02:48,239 --> 00:02:53,819
like break lines and spaces, then you
need to pass here a function,

28
00:02:53,819 --> 00:02:58,950
a function that ignores those lines. We don't
have that scenario for now so let's keep

29
00:02:58,950 --> 00:03:03,630
it simple. We passed None there for that
argument and then you pass the two string, so you

30
00:03:03,630 --> 00:03:09,299
want to compare the word rain with a
double N against the word, the actual

31
00:03:09,299 --> 00:03:16,410
word rain and that will return a
sequence matcher object which is nothing

32
00:03:16,410 --> 00:03:21,120
interesting so you need to apply the
ratio method to that to get the actual

33
00:03:21,120 --> 00:03:26,880
ratio. So this indicates similarity
between these two strings in a scale

34
00:03:26,880 --> 00:03:32,940
from 0 to 1 so this says that
these are quite similar. Now this is

35
00:03:32,940 --> 00:03:40,190
about getting the similarity between two
strings, but what we need instead is

36
00:03:40,190 --> 00:03:47,700
basically we have a list a sequence of
strings so we have this keys of

37
00:03:47,700 --> 00:03:53,639
dictionary, we have a dictionary with lots of
keys and the user passes a word, let's

38
00:03:53,639 --> 00:04:01,290
say rain with double N and
you need to compare that word with all

39
00:04:01,290 --> 00:04:07,199
those keys of that dictionary because you
cannot compare rain with double N with

40
00:04:07,199 --> 00:04:12,380
rain with one N in your program
because you don't know that this

41
00:04:12,380 --> 00:04:19,160
is actually similar to this so
is the reverse problem so to say. But

42
00:04:19,160 --> 00:04:29,210
difflib has another feature for that
and it's called get_close_matches, like

43
00:04:29,210 --> 00:04:34,040
that, so you need to import that from difflibb.
You need to import get_close_matches but

44
00:04:34,040 --> 00:04:39,000
I'll consume this feature in the next
lecture. See you there!

