Skip to content

Instantly share code, notes, and snippets.

@e-p-armstrong
Created May 6, 2024 03:24
Show Gist options
  • Save e-p-armstrong/ea19ece540894232416f82cfa8e05565 to your computer and use it in GitHub Desktop.
Save e-p-armstrong/ea19ece540894232416f82cfa8e05565 to your computer and use it in GitHub Desktop.
def has_sequential_chars(string1, string2, n):
"""
Check if any n sequential characters from string1 appear in string2.
Args:
string1 (str): The first string to check.
string2 (str): The second string in which to look for sequences.
n (int): The length of the sequence to check.
Returns:
bool: True if any n sequential characters from string1 are found in string2, False otherwise.
"""
# Check if n is larger than the length of string1.
if n > len(string1):
return False, ""
# Iterate over string1 and check for each n-length substring in string2
comparison_string = ""
for i in range(len(string1) - n + 1):
comparison_string = string1[i : i + n]
if comparison_string in string2:
return True, comparison_string
return False, comparison_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment