input: Write a python function to calculate the cosine similarity between two vectors.
  assert cosine_similarity([1, 0, -1], [-1, -1, 0]) == -0.5
  assert cosine_similarity([1, 2, 3], [4, 5, 6]) == 0.9746318461970762
  assert cosine_similarity([1, 0], [0, 1]) == 0.0
  assert cosine_similarity([1, 2, 3], [1, 2, 3]) == 1.0
output: def cosine_similarity(vec1, vec2):
      from math import sqrt
      dot_product = sum(v1 * v2 for v1, v2 in zip(vec1, vec2))
      magnitude1 = sqrt(sum(v1 * v1 for v1 in vec1))
      magnitude2 = sqrt(sum(v2 * v2 for v2 in vec2))
      if magnitude1 == 0 or magnitude2 == 0:
          return 0.0
      return dot_product / (magnitude1 * magnitude2)