Euclidean distance calculator

Report a typo

Complete the function euclidean_distance() to calculate the Euclidean distance between two sentences using their corresponding bag-of-words representations provided below.

The function's input consists of two lists, each list consisting of integers. The output should be the Euclidean distance as a float, rounded to 4 decimals.

Example of calculation:

doc_1 = "Euclidean distance is a semantic similarity metric."
doc_2 = "Euclidean distance is not a lexical similarity metric"

Their corresponding bag-of-words representations as input:

doc_1 = [1, 1, 0, 1, 0, 1, 2]
doc_2 = [1, 1, 1, 1, 1, 0, 2]

The Euclidean distance between them is 1.7321.

Sample Input 1:

1 1000 0 1 0 1 -1
1 1 1 0 1 0 -1

Sample Output 1:

999.002
Write a program in Python 3
def euclidean_distance(doc_1: list, doc_2: list) -> float:
...
return distance

doc_1 = [int(i) for i in input().split()]
doc_2 = [int(i) for i in input().split()]
print(euclidean_distance(doc_1, doc_2))
___

Create a free account to access the full topic