File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1
1
from .palindrome_check import *
2
-
2
+ from . hamming_dist import *
Original file line number Diff line number Diff line change
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Binary search works for a sorted array.
4
+ # The All ▲lgorithms library for python
5
+ #
6
+ # Contributed by: ninexball
7
+ # Github: @ninexball
8
+ #
9
+
10
+ def hamming_dist (seq1 : str , seq2 : str ) -> int :
11
+ """Compare hamming distance of two strings"""
12
+ if len (seq1 ) != len (seq2 ):
13
+ raise ValueError ("length of strings are not the same" )
14
+ return sum (c1 != c2 for c1 , c2 in zip (seq1 , seq2 ))
Original file line number Diff line number Diff line change
1
+ # Hamming Distance
2
+
3
+ In informatics, Hamming distance is the number of positions where the characters differ between two strings of equal length
4
+
5
+ ## Install
6
+
7
+ ```
8
+ pip install allalgorithms
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ >>> from allalgorithms.sorting import hamming_dist
15
+
16
+ >>> hamming_dist("hello world", "hello wario")
17
+ 3
18
+ ```
19
+
20
+ ## API
21
+
22
+ ### hamming_dist(seq1, seq2)
23
+
24
+ > Returns an integer
25
+
26
+ > Raises a ValueError if strings are of unequal length
27
+
28
+ ##### Params:
29
+
30
+ - ` seq1 ` : first string to compare
31
+ - ` seq2 ` : second string to compare
32
+
You can’t perform that action at this time.
0 commit comments