{"id":10105,"library":"pylcs","title":"pylcs - Longest Common Subsequence","description":"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.","status":"maintenance","version":"0.1.1","language":"en","source_language":"en","source_url":"https://github.com/kuangkzh/pylcs","tags":["string-algorithms","lcs","cpp-binding","performance","sequence-alignment"],"install":[{"cmd":"pip install pylcs","lang":"bash","label":"Install pylcs"}],"dependencies":[],"imports":[{"symbol":"lcs","correct":"from pylcs import lcs"}],"quickstart":{"code":"from pylcs import lcs\n\nstr1 = \"ABCBDAB\"\nstr2 = \"BDCABA\"\n\n# Get the length of the longest common subsequence\nlcs_length = lcs(str1, str2)\n\nprint(f\"Strings: '{str1}', '{str2}'\")\nprint(f\"Length of LCS: {lcs_length}\")\n\n# Example with different strings\nstr3 = \"AGGTAB\"\nstr4 = \"GXTXAYB\"\nprint(f\"\\nStrings: '{str3}', '{str4}'\")\nprint(f\"Length of LCS: {lcs(str3, str4)}\")","lang":"python","description":"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."},"warnings":[{"fix":"For the actual LCS string, consider using `difflib.SequenceMatcher` from the standard library or a custom implementation if performance is critical.","message":"pylcs only returns the length of the LCS, not the actual subsequence itself. If you need the subsequence string, you'll need to implement or use another library's function for reconstruction.","severity":"gotcha","affected_versions":"0.1.x"},{"fix":"Always cast inputs to strings before passing them to `pylcs.lcs`, e.g., `lcs(str(item1), str(item2))`.","message":"The library primarily accepts string inputs. Passing non-string types (e.g., lists, numbers) will result in a TypeError. Ensure both arguments passed to `lcs` are strings.","severity":"gotcha","affected_versions":"0.1.x"},{"fix":"Ensure you have a C++ compiler installed. On Windows, install 'Build Tools for Visual Studio'. On Linux/macOS, install `build-essential` or Xcode command line tools respectively.","message":"As a C++ extension, installation of `pylcs` requires a C++ compiler (like GCC on Linux/macOS or MSVC on Windows) to be present and configured on your system. Installation might fail without it.","severity":"gotcha","affected_versions":"0.1.x"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install pylcs` to install the package. If it still fails, check for C++ compiler requirements.","cause":"The 'pylcs' package is not installed in your current Python environment, or the installation failed.","error":"ModuleNotFoundError: No module named 'pylcs'"},{"fix":"Ensure you pass two string arguments to `lcs`, e.g., `lcs(string_a, string_b)`.","cause":"The `lcs` function was called with an incorrect number of arguments. It requires exactly two string arguments.","error":"TypeError: lcs() takes exactly 2 arguments (1 given)"},{"fix":"Convert all inputs to strings before calling `lcs`. For example, `lcs(str(my_list_item), str(my_other_item))`.","cause":"You attempted to pass a non-string type (e.g., a list, int, or dict) to the `lcs` function, which strictly expects string inputs.","error":"TypeError: argument 1 must be str, not list"}]}