Skip to content

Commit

Permalink
0.1.14 (2023-11-26)
Browse files Browse the repository at this point in the history
-------------------
* [new] vlist.is_in()
* [fix] requirements tomli
  • Loading branch information
vladimirs-git committed Nov 26, 2023
1 parent 3c068f4 commit 64851b2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
CHANGELOG
=========

0.1.14 (2023-11-26)
-------------------
* [new] vlist.is_in()
* [fix] requirements tomli


0.1.13 (2023-11-04)
-------------------
* [new] vlist.replace()
Expand Down
17 changes: 16 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ or install the package from github.com release

.. code:: bash
pip install https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.13.tar.gz
pip install https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.14.tar.gz
or install the package from github.com repository

Expand Down Expand Up @@ -267,6 +267,21 @@ Return
assert vlist.flatten([1, [2, [3]], 4, [5, [6]]]) == [1, 2, 3, 4, 5, 6]
is_in(items1, items2)
---------------------
Check if any item in items1 is present in items2.

=========== ====== ===================================================================================
Parameter Type Description
=========== ====== ===================================================================================
items1 *list* A list of items.
items2 *list* A list of items.
=========== ====== ===================================================================================

Return
*bool* True if any item in items1 is present in items2, False otherwise.


no_dupl(items)
--------------
Remove duplicates from a list of items.
Expand Down
12 changes: 0 additions & 12 deletions __init__.py

This file was deleted.

8 changes: 7 additions & 1 deletion examples/vlist_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
# Convert a multidimensional list to a flattened list.
assert vlist.flatten([1, [2, [3]], 4, [5, [6]]]) == [1, 2, 3, 4, 5, 6]

# Check is one of items in the items1 is present in the items2.
assert vlist.is_in(items1=[1, 2], items2=[2, 3]) is True
assert vlist.is_in(items1=[1, 2], items2=[3, 4]) is False

# Remove duplicates from a list of items.
assert vlist.no_dupl(items=[1, 2, 1]) == [1, 2]

# Replace one item with another.
assert vlist.replace(items=[1, 2, 3], old=2, new=4) == [1, 4, 3]
items = [1, 2, 3]
vlist.replace(items=items, old=2, new=4)
assert items == [1, 4, 3]

# Split string by punctuation chars.
assert vlist.split(text="1; 2_3-4X5,6", chars="_X", ignore=",") == ["1", "2", "3", "4", "5,6"]
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vhelpers"
version = "0.1.13"
version = "0.1.14"
description = "Often used functions in vladimirs-git projects"
authors = ["Vladimir Prusakov <vladimir.prusakovs@gmail.com>"]
readme = "README.rst"
Expand All @@ -15,8 +15,10 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Natural Language :: English",
]

[tool.poetry.dependencies]
python = "^3.8"
tomli = "^2.0.1"

[tool.poetry.group.test.dependencies]
pytest = "^7.4.2"
Expand All @@ -41,7 +43,7 @@ test = ["pytest"]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/vladimirs-git/vhelpers/issues"
"Download URL" = "https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.13.tar.gz"
"Download URL" = "https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.14.tar.gz"


[build-system]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_vlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ def test__flatten(items, expected):
assert actual == expected


@pytest.mark.parametrize("items1, items2, expected", [
([], [], False),
([], [1], False),
([1, 2], [], False),
([1, 2], [3], False),
([1, 2], [1, 3], True),
([1, 2], [2, 3], True),
])
def test__is_in(items1, items2, expected):
"""vlist.is_in()."""
actual = vlist.is_in(items1=items1, items2=items2)
assert actual == expected


@pytest.mark.parametrize("items, expected", [
([], []),
(["a", "b", "a"], ["a", "b"]),
Expand Down
20 changes: 19 additions & 1 deletion vhelpers/vlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ def _flatten(items: Sequence, ignore_types=(str, bytes)) -> Generator:
yield item


def is_in(items1: list, items2: list) -> bool:
"""Check if any item in items1 is present in items2.
:param items1: A list of items.
:param items2: A list of items.
:return: True if any item in items1 is present in items2, False otherwise.
:example:
is_in(items1=[1, 2], items2=[2, 3]) is True
is_in(items1=[1, 2], items2=[2, 3]) is True
"""
for items in items1:
if items in items2:
return True
return False


def no_dupl(items: SeqTy) -> ListTy:
"""Remove duplicates from a list of items.
Expand All @@ -98,7 +114,9 @@ def replace(items: list, old: Any, new: Any) -> None:
:param new: The item to replace with.
:return: None. Update items.
:example:
replace(items=[1, 2, 3], old=2, new=4) -> [1, 4, 3]
items = [1, 2, 3]
vlist.replace(items=items, old=2, new=4)
assert items == [1, 4, 3]
"""
if old in items:
idx = items.index(old)
Expand Down

0 comments on commit 64851b2

Please sign in to comment.