Calculate the dot product of two vectors. The dot product is the sum of element-wise products and is a fundamental operation in linear algebra.
def dot_product(v1, v2):
if len(v1) != len(v2):
raise ValueError("Vectors must have the same length")
result = sum(a * b for a, b in zip(v1, v2))
return result