Download benchmarks/quixbugs/python/levenshtein.py from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/quixbugs/python/levenshtein.py
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/benchmarks/quixbugs/python/levenshtein.py
-
curl -L -o levenshtein.py https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/quixbugs/python/levenshtein.py
1.02 kB
| def levenshtein(source, target): | |
| if source == '' or target == '': | |
| return len(source) or len(target) | |
| elif source[0] == target[0]: | |
| return levenshtein(source[1:], target[1:]) | |
| else: | |
| return 1 + min( | |
| levenshtein(source, target[1:]), | |
| levenshtein(source[1:], target[1:]), | |
| levenshtein(source[1:], target) | |
| ) | |
| """ | |
| Levenshtein Distance | |
| Calculates the Levenshtein distance between two strings. The Levenshtein distance is defined as the minimum amount of single-character edits (either removing a character, adding a character, or changing a character) necessary to transform a source string into a target string. | |
| Input: | |
| source: The string you begin with. | |
| target: The string to transform into. | |
| Output: | |
| The Levenshtein distance between the source and target. | |
| Example: | |
| electron can be transformed into neutron by removing the e, turning the l into n, and turning the c into u. | |
| >>> levenshtein(electron, neutron) | |
| 3 | |
| """ | |