Skip to main content

Computing the longest common subsequence of a pair of sequences

Project description

lcs2

lcs2 is a Python package which helps compute the longest common subsequence of a pair of sequences.

Installation

pip install lcs2

Reference

The package provides the following functions:

Function Signature Result
lcs Iterable[T], Iterable[T] -> list[T] Longest common subsequence (LCS)
lcs_indices Iterable[T], Iterable[T] -> list[tuple[int, int]] Indices of the LCS
lcs_length Iterable[T], Iterable[T] -> int Length of the LCS

Calling lcs_length(a, b) is somewhat more efficient than simply using len(lcs(a, b)).

Sample Usage

from lcs2 import lcs, lcs_indices, lcs_length

a = 'Hello, world!'
b = 'Foobar'
print(lcs(a, b))  # ['o', 'o', 'r']
print(lcs_indices(a, b))  # [(4, 1), (8, 2), (9, 5)]
print(lcs_length(a, b))  # 3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lcs2-1.0.1.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

lcs2-1.0.1-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page