BeginnerCoder

Lesson 3 — Similarity

How far apart are two points?

Many models decide that two examples are "similar" when they are close. The usual measure is Euclidean distance — the straight-line distance you would measure with a ruler. For each coordinate you take the difference, square it, add those squares up, and take the square root.

# (0, 0) to (3, 4): (3² + 4²) ** 0.5 = 5.0

zip(a, b) walks two lists side by side, and ** 0.5 is the square root.

Why it matters: distance is the heart of nearest-neighbour search, clustering and recommendation systems ("customers like you also bought…").

Want it another way?
Task

Finish dist(a, b) so it returns the Euclidean distance. Both checks should print 5.0.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.