Created
May 6, 2024 03:24
-
-
Save e-p-armstrong/ea19ece540894232416f82cfa8e05565 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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