-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHamming_distance.py
More file actions
13 lines (11 loc) · 993 Bytes
/
Copy pathHamming_distance.py
File metadata and controls
13 lines (11 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
def Hamming_distance(p, q): #Function takes 2 parameters p and q which are strings
string_p = len(p) #string_p contains the length of string p
string_q = len(q) #string_q contains the length of string q
mismatches = 0 #initializing the variable mismatch to 0. Incremented everytime when a mismatch is found
if not string_p == string_q: #Checking wether strings p and q of equal length
return "Strings of unequal size" #If the condition fails, returning the message of unequal size
else:
for i in range(string_p): # taking any of the either string and iterating to the whole length
if p[i] != q[i]: # checking if each character of p not matching with each and every character of q
mismatches += 1 # when the above condition is True mismatch is incremented
return mismatches # Return all the mismatch found in the strings