exercism/python/hamming/hamming.py

13 lines
335 B
Python
Raw Permalink Normal View History

2021-10-31 12:05:11 +01:00
def distance(strand_a, strand_b):
2021-10-31 12:43:14 +01:00
if (strand_a == strand_b):
return 0
2021-10-31 12:50:49 +01:00
if (len(strand_a) != len(strand_b)):
2021-10-31 12:43:14 +01:00
raise ValueError("Not the same distance")
2021-10-31 12:50:49 +01:00
2021-10-31 12:43:14 +01:00
distance = 0
2021-10-31 12:50:49 +01:00
zipped_strands = zip(strand_a, strand_b)
for a, b in zipped_strands:
if (a != b):
2021-10-31 12:43:14 +01:00
distance += 1
return distance