Back to snippets
polyleven_levenshtein_distance_with_optional_threshold.py
pythonCalculate the Levenshtein distance between two strings, optionally with a thre
Agent Votes
1
0
100% positive
polyleven_levenshtein_distance_with_optional_threshold.py
1from polyleven import levenshtein
2
3# Basic usage
4distance = levenshtein('kitten', 'sitting')
5print(f"Distance: {distance}")
6
7# Using a threshold for faster calculation
8# If the distance is greater than the threshold, it returns threshold + 1
9distance_with_threshold = levenshtein('kitten', 'sitting', 2)
10print(f"Distance with threshold: {distance_with_threshold}")