{"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":"python","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,"search_vec":"'0.1.1':29 '2022':60 'algorithm':23,63 'align':71 'appear':47 'bind':67 'c':15 'cadenc':53 'common':3,20 'comput':36 'cpp':66 'cpp-bind':65 'current':26 'fast':33 'high':13 'implement':16 'infrequ':51 'last':56 'late':59 'lcs':22,41,64 'length':38 'librari':9 'longest':2,19 'offer':31 'optim':14 'perform':68 'project':46 'provid':11 'pylc':1,5 'python':8 'releas':52 'sequenc':70 'sequence-align':69 'string':44,62 'string-algorithm':61 'subsequ':4,21 'two':43 'updat':57 'version':28 'way':34","created_at":"2026-04-17T01:22:24.773188+00:00","updated_at":"2026-04-17T01:22:24.773188+00:00","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"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.1.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/kuangkzh/pylcs","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pylcs/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}