Skip to content

Commit 2358f9a

Browse files
Update README.md
1 parent 6948efb commit 2358f9a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,3 +1107,23 @@ filtered_df = df.filter(regex=regex_pattern, axis=1)
11071107

11081108
print(filtered_df)
11091109
```
1110+
1111+
#### Compare two strings using SequenceMatcher and print the differences.
1112+
```python
1113+
from difflib import SequenceMatcher
1114+
1115+
def compare_strings(str1, str2):
1116+
"""
1117+
Compare two strings using SequenceMatcher and print the differences.
1118+
1119+
Args:
1120+
str1 (str): The first string to compare.
1121+
str2 (str): The second string to compare.
1122+
"""
1123+
matcher = SequenceMatcher(None, str1, str2)
1124+
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
1125+
print(f"{tag}: '{str1[i1:i2]}' vs '{str2[j1:j2]}'")
1126+
1127+
# Example usage:
1128+
# compare_strings("string1", "string2")
1129+
```

0 commit comments

Comments
 (0)