mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Set the Python file maximum line length to 88 characters (#2122)
* flake8 --max-line-length=88
* fixup! Format Python code with psf/black push
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@@ -41,7 +41,9 @@ class BoyerMooreSearch:
|
||||
return -1
|
||||
|
||||
def mismatch_in_text(self, currentPos):
|
||||
""" finds the index of mis-matched character in text when compared with pattern from last
|
||||
"""
|
||||
find the index of mis-matched character in text when compared with pattern
|
||||
from last
|
||||
|
||||
Parameters :
|
||||
currentPos (int): current index position of text
|
||||
|
||||
@@ -14,8 +14,8 @@ def is_palindrome(s: str) -> bool:
|
||||
>>> is_palindrome("Mr. Owl ate my metal worm?")
|
||||
True
|
||||
"""
|
||||
# Since Punctuation, capitalization, and spaces are usually ignored while checking Palindrome,
|
||||
# we first remove them from our string.
|
||||
# Since Punctuation, capitalization, and spaces are usually ignored while checking
|
||||
# Palindrome, we first remove them from our string.
|
||||
s = "".join([character for character in s.lower() if character.isalnum()])
|
||||
return s == s[::-1]
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
def jaro_winkler(str1: str, str2: str) -> float:
|
||||
"""
|
||||
Jaro–Winkler distance is a string metric measuring an edit distance between two sequences.
|
||||
Jaro–Winkler distance is a string metric measuring an edit distance between two
|
||||
sequences.
|
||||
Output value is between 0.0 and 1.0.
|
||||
|
||||
>>> jaro_winkler("martha", "marhta")
|
||||
|
||||
@@ -5,11 +5,11 @@ def kmp(pattern, text):
|
||||
|
||||
1) Preprocess pattern to identify any suffixes that are identical to prefixes
|
||||
|
||||
This tells us where to continue from if we get a mismatch between a character in our pattern
|
||||
and the text.
|
||||
This tells us where to continue from if we get a mismatch between a character
|
||||
in our pattern and the text.
|
||||
|
||||
2) Step through the text one character at a time and compare it to a character in the pattern
|
||||
updating our location within the pattern if necessary
|
||||
2) Step through the text one character at a time and compare it to a character in
|
||||
the pattern updating our location within the pattern if necessary
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ def lower(word: str) -> str:
|
||||
'what'
|
||||
"""
|
||||
|
||||
# converting to ascii value int value and checking to see if char is a capital letter
|
||||
# if it is a capital letter it is getting shift by 32 which makes it a lower case letter
|
||||
# converting to ascii value int value and checking to see if char is a capital
|
||||
# letter if it is a capital letter it is getting shift by 32 which makes it a lower
|
||||
# case letter
|
||||
return "".join(
|
||||
chr(ord(char) + 32) if 65 <= ord(char) <= 90 else char for char in word
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""
|
||||
Algorithm for calculating the most cost-efficient sequence for converting one string into another.
|
||||
Algorithm for calculating the most cost-efficient sequence for converting one string
|
||||
into another.
|
||||
The only allowed operations are
|
||||
---Copy character with cost cC
|
||||
---Replace character with cost cR
|
||||
|
||||
@@ -8,15 +8,18 @@ def rabin_karp(pattern, text):
|
||||
"""
|
||||
The Rabin-Karp Algorithm for finding a pattern within a piece of text
|
||||
with complexity O(nm), most efficient when it is used with multiple patterns
|
||||
as it is able to check if any of a set of patterns match a section of text in o(1) given the precomputed hashes.
|
||||
as it is able to check if any of a set of patterns match a section of text in o(1)
|
||||
given the precomputed hashes.
|
||||
|
||||
This will be the simple version which only assumes one pattern is being searched for but it's not hard to modify
|
||||
This will be the simple version which only assumes one pattern is being searched
|
||||
for but it's not hard to modify
|
||||
|
||||
1) Calculate pattern hash
|
||||
|
||||
2) Step through the text one character at a time passing a window with the same length as the pattern
|
||||
calculating the hash of the text within the window compare it with the hash of the pattern. Only testing
|
||||
equality if the hashes match
|
||||
2) Step through the text one character at a time passing a window with the same
|
||||
length as the pattern
|
||||
calculating the hash of the text within the window compare it with the hash
|
||||
of the pattern. Only testing equality if the hashes match
|
||||
"""
|
||||
p_len = len(pattern)
|
||||
t_len = len(text)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
def split(string: str, separator: str = " ") -> list:
|
||||
"""
|
||||
Will split the string up into all the values separated by the separator (defaults to spaces)
|
||||
Will split the string up into all the values separated by the separator
|
||||
(defaults to spaces)
|
||||
|
||||
>>> split("apple#banana#cherry#orange",separator='#')
|
||||
['apple', 'banana', 'cherry', 'orange']
|
||||
|
||||
@@ -14,7 +14,8 @@ def upper(word: str) -> str:
|
||||
"""
|
||||
|
||||
# converting to ascii value int value and checking to see if char is a lower letter
|
||||
# if it is a capital letter it is getting shift by 32 which makes it a capital case letter
|
||||
# if it is a capital letter it is getting shift by 32 which makes it a capital case
|
||||
# letter
|
||||
return "".join(
|
||||
chr(ord(char) - 32) if 97 <= ord(char) <= 122 else char for char in word
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user