Levenshtein Distance

Category: Arithmetic

Status: Registered and callable in the CyberChef 11.3.0 compatibility inventory.

Input / output: string → number

Background: https://wikipedia.org/wiki/Levenshtein_distance

What it does

Levenshtein Distance (also known as Edit Distance) is a string metric to measure a difference between two strings that counts operations (insertions, deletions, and substitutions) on single character that are required to change one string to another.

Note

Status here means the operation name is implemented and callable. It does not by itself promise byte-for-byte parity for every upstream option. See Compatibility and current status for the verified scope and known boundaries.

Arguments and options

Arguments are positional. Keep their order when using bake() or Pipeline.then().

Index

Name

UI type

PyChef default

Accepted values / format

0

Sample delimiter

binaryString

'\\n'

'\\n'

1

Insertion cost

number

1

A Python integer or floating-point value

2

Deletion cost

number

1

A Python integer or floating-point value

3

Substitution cost

number

1

A Python integer or floating-point value

Recipe template

Important

This is a call template built from the documented defaults. Replace placeholder values such as empty keys, paths, patterns, or lookup data before running it.

from pychef import bake

input_value = "example"
args = ['\\n', 1, 1, 1]
result = bake(input_value, [{"op": 'Levenshtein Distance', "args": args}])
print(result)

Pipeline example

from pychef import Pipeline

args = ['\\n', 1, 1, 1]
transform = Pipeline().then('Levenshtein Distance', *args)
result = transform("example")

Direct call

pychef.ops.run_operation runs any registered operation as a plain function, under the active ExecutionPolicy (safe defaults, no network):

from pychef.ops import run_operation

args = ['\\n', 1, 1, 1]
result = run_operation('Levenshtein Distance', "example", args=args)

Common operations also have typed helpers in Direct operations.

Low-level operation module

Warning

The module below is an internal implementation detail. It applies no execution policy, resource limits, or error sanitization; prefer bake(), Pipeline, or pychef.ops for application code.

The registered entry point lives in pychef.operations.by_operation.levenshtein_distance. Direct calls receive the input value and a positional argument tuple:

from pychef.operations.by_operation.levenshtein_distance import run

result = run("example", tuple(['\\n', 1, 1, 1]))
pychef.operations.by_operation.levenshtein_distance.run(value, args)

Run this operation using its shared internal implementation.

Parameters:
  • value (str | bytes)

  • args (Sequence[Any])

Return type:

str | bytes