pylcs - Longest Common Subsequence

0.1.1 · maintenance · verified Fri Apr 17

pylcs is a Python library that provides a highly optimized C++ implementation of the Longest Common Subsequence (LCS) algorithm. It is currently at version 0.1.1 and offers a fast way to compute the length of the LCS between two strings. The project appears to have an infrequent release cadence, with the last update in late 2022.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import the `lcs` function and use it to calculate the length of the longest common subsequence between two strings. The function expects two string arguments.

from pylcs import lcs

str1 = "ABCBDAB"
str2 = "BDCABA"

# Get the length of the longest common subsequence
lcs_length = lcs(str1, str2)

print(f"Strings: '{str1}', '{str2}'")
print(f"Length of LCS: {lcs_length}")

# Example with different strings
str3 = "AGGTAB"
str4 = "GXTXAYB"
print(f"\nStrings: '{str3}', '{str4}'")
print(f"Length of LCS: {lcs(str3, str4)}")

view raw JSON →