﻿ NLTK corpus: Compare the similarity of two given verbs - w3resource # NLTK corpus: Compare the similarity of two given verbs

## NLTK corpus: Exercise-10 with Solution

Write a Python NLTK program to compare the similarity of two given verbs.

Sample Solution:

Python Code :

``````from nltk.corpus import wordnet
print("\nComparing go anb return:")
v1 = wordnet.synset('go.v.01')
v2 = wordnet.synset('return.v.01')
print(v1.wup_similarity(v2))

v2 = wordnet.synset('sell.v.01')
print(v1.wup_similarity(v2))

print("\nComparing begin anb start:")
v1 = wordnet.synset('begin.v.01')
v2 = wordnet.synset('start.v.01')
print(v1.wup_similarity(v2))
``````

Sample Output:

```Comparing go anb return:
0.6666666666666666

0.2857142857142857

Comparing begin anb start:
1.0
```

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## Python: Tips of the Day

Get the Key Whose Value Is Maximal in a Dictionary:

```>>> model_scores = {'model_a': 100, 'model_z': 198, 'model_t': 150}
>>> # workaround
>>> keys, values = list(model_scores.keys()), list(model_scores.values())
>>> keys[values.index(max(values))]
'model_z'
>>> # one-line
>>> max(model_scores, key=model_scores.get)
'model_z'
```