listdiffer


Namelistdiffer JSON
Version 0.2.0 PyPI version JSON
download
home_page
SummaryGenerate diffs on lists of objects
upload_time2024-01-07 21:42:35
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2024 listdiffer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords lcs diff delta
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # List Differ

Version: 0.2.0

Calculates longest common sequence on text, lists of numbers or characters, or lists of objects.

When comparing objects, make sure that the objects are hashable, i.e. override the `__hash()__` method of the class.
It is also a good idea to override the `__eq()__` method if you have some custom logic for comparing items.
This could be the case if your business logic considers close values as similar.

If you want to compare two strings ignoring casing, then simply call `lower` on each string before passing as argument.

## Examples

### Example 1 - Strings

Calculate a diff between two strings

#### Same strings

```python
from listdiffer import differ

first = 'string'
second = 'string'
diff = differ.diff_text(first, second, False, False)

assert len(diff) == 0
```

#### Different strings

```python
from listdiffer import differ

first = 'first string'
second = 'second string'
diff = differ.diff_text(first, second, False, False)

assert len(diff) == 1
```

### Example 2 - List of integers

Calculate a diff between two strings

#### Same lists

```python
from listdiffer import differ

first = [1, 2, 3]
second = [1, 2, 3]
d = differ.diff(first, second)

assert len(d) == 0
```

#### Different lists

```python
from listdiffer import differ

first = [1, 2, 3]
second = [1, 2, 4]
d = differ.diff(first, second)

assert len(d) == 1
```

## Example 3 - Lists of objects

### Same lists

```python
from listdiffer import differ

@dataclass
class TestItem:
    text: str
    value: int

    def __eq__(self, other):
        return self.text == other.text and self.value == other.value

    def __hash__(self):
        return hash((self.text, self.value))

source = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3)]
compare = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3)]
result = differ.diff(source, compare)

assert len(result) == 0
```

### Different lists

```python
from listdiffer import differ

@dataclass
class TestItem:
    text: str
    value: int

    def __eq__(self, other):
        return self.text == other.text and self.value == other.value

    def __hash__(self):
        return hash((self.text, self.value))

source = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3)]
compare = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3), TestItem('test', 4)]
result = differ.diff(source, compare)

assert len(result) == 1
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "listdiffer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "lcs,diff,delta",
    "author": "",
    "author_email": "Jacob Reimers <pypi@reimers.io>",
    "download_url": "https://files.pythonhosted.org/packages/79/68/f1387d7970e67f9f50379759d973fe0db740851d5687aed37de8b42c85fb/listdiffer-0.2.0.tar.gz",
    "platform": null,
    "description": "# List Differ\n\nVersion: 0.2.0\n\nCalculates longest common sequence on text, lists of numbers or characters, or lists of objects.\n\nWhen comparing objects, make sure that the objects are hashable, i.e. override the `__hash()__` method of the class.\nIt is also a good idea to override the `__eq()__` method if you have some custom logic for comparing items.\nThis could be the case if your business logic considers close values as similar.\n\nIf you want to compare two strings ignoring casing, then simply call `lower` on each string before passing as argument.\n\n## Examples\n\n### Example 1 - Strings\n\nCalculate a diff between two strings\n\n#### Same strings\n\n```python\nfrom listdiffer import differ\n\nfirst = 'string'\nsecond = 'string'\ndiff = differ.diff_text(first, second, False, False)\n\nassert len(diff) == 0\n```\n\n#### Different strings\n\n```python\nfrom listdiffer import differ\n\nfirst = 'first string'\nsecond = 'second string'\ndiff = differ.diff_text(first, second, False, False)\n\nassert len(diff) == 1\n```\n\n### Example 2 - List of integers\n\nCalculate a diff between two strings\n\n#### Same lists\n\n```python\nfrom listdiffer import differ\n\nfirst = [1, 2, 3]\nsecond = [1, 2, 3]\nd = differ.diff(first, second)\n\nassert len(d) == 0\n```\n\n#### Different lists\n\n```python\nfrom listdiffer import differ\n\nfirst = [1, 2, 3]\nsecond = [1, 2, 4]\nd = differ.diff(first, second)\n\nassert len(d) == 1\n```\n\n## Example 3 - Lists of objects\n\n### Same lists\n\n```python\nfrom listdiffer import differ\n\n@dataclass\nclass TestItem:\n    text: str\n    value: int\n\n    def __eq__(self, other):\n        return self.text == other.text and self.value == other.value\n\n    def __hash__(self):\n        return hash((self.text, self.value))\n\nsource = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3)]\ncompare = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3)]\nresult = differ.diff(source, compare)\n\nassert len(result) == 0\n```\n\n### Different lists\n\n```python\nfrom listdiffer import differ\n\n@dataclass\nclass TestItem:\n    text: str\n    value: int\n\n    def __eq__(self, other):\n        return self.text == other.text and self.value == other.value\n\n    def __hash__(self):\n        return hash((self.text, self.value))\n\nsource = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3)]\ncompare = [TestItem('test', 1), TestItem('test', 2), TestItem('test', 3), TestItem('test', 4)]\nresult = differ.diff(source, compare)\n\nassert len(result) == 1\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 listdiffer  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Generate diffs on lists of objects",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/jjrdk/listdiffer"
    },
    "split_keywords": [
        "lcs",
        "diff",
        "delta"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47e59aa4b00c7a86bf3194a211c87841c06f92fc07c4ba63079b2bdbcff63e35",
                "md5": "8041b59bd347e2ee4c5663702832ecf7",
                "sha256": "fac2934ddd52294f85f80471c4854cbcb3e04494c8bb4262f9625e0901d7ac3c"
            },
            "downloads": -1,
            "filename": "listdiffer-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8041b59bd347e2ee4c5663702832ecf7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8403,
            "upload_time": "2024-01-07T21:42:34",
            "upload_time_iso_8601": "2024-01-07T21:42:34.331713Z",
            "url": "https://files.pythonhosted.org/packages/47/e5/9aa4b00c7a86bf3194a211c87841c06f92fc07c4ba63079b2bdbcff63e35/listdiffer-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7968f1387d7970e67f9f50379759d973fe0db740851d5687aed37de8b42c85fb",
                "md5": "2f0d3e464436a9ab469cd87bddd914a8",
                "sha256": "ae5717b16eb340c2313d032d3f4f75a8afa6bb393995307df8d215e4f0bf1c9a"
            },
            "downloads": -1,
            "filename": "listdiffer-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2f0d3e464436a9ab469cd87bddd914a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9710,
            "upload_time": "2024-01-07T21:42:35",
            "upload_time_iso_8601": "2024-01-07T21:42:35.748390Z",
            "url": "https://files.pythonhosted.org/packages/79/68/f1387d7970e67f9f50379759d973fe0db740851d5687aed37de8b42c85fb/listdiffer-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-07 21:42:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jjrdk",
    "github_project": "listdiffer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "listdiffer"
}
        
Elapsed time: 0.17103s