Skip to content

Commit

Permalink
0.1.13 (2023-11-04)
Browse files Browse the repository at this point in the history
-------------------
* [fix] vlist.replace()
  • Loading branch information
vladimirs-git committed Nov 4, 2023
1 parent ca316a0 commit 3c068f4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CHANGELOG
=========

0.1.12 (2023-11-04)
0.1.13 (2023-11-04)
-------------------
* [new] vlist.replace()

Expand Down
12 changes: 6 additions & 6 deletions 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.12.tar.gz
pip install https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.13.tar.gz
or install the package from github.com repository

Expand Down Expand Up @@ -288,16 +288,16 @@ Return
assert vlist.no_dupl(items=[1, 2, 1]) == [1, 2]
replace(items, item, other)
---------------------------
replace(items, old, new)
------------------------
Replace one item with another.

=========== ====== ===================================================================================
Parameter Type Description
=========== ====== ===================================================================================
items *list* The list of items where need replace item.
item *Any* The item to be replaced.
other *Any* The item to replace with.
old *Any* The item to be replaced.
new *Any* The item to replace with.
=========== ====== ===================================================================================

Return
Expand All @@ -307,7 +307,7 @@ Return
from vhelpers import vlist
assert vlist.replace(items=[1, 2, 3], item=2, other=4) == [1, 4, 3]
assert vlist.replace(items=[1, 2, 3], old=2, new=4) == [1, 4, 3]
split(text, chars, ignore)
Expand Down
2 changes: 1 addition & 1 deletion examples/vlist_.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
assert vlist.no_dupl(items=[1, 2, 1]) == [1, 2]

# Replace one item with another.
assert vlist.replace(items=[1, 2, 3], item=2, other=4) == [1, 4, 3]
assert vlist.replace(items=[1, 2, 3], old=2, new=4) == [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
4 changes: 2 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.12"
version = "0.1.13"
description = "Often used functions in vladimirs-git projects"
authors = ["Vladimir Prusakov <vladimir.prusakovs@gmail.com>"]
readme = "README.rst"
Expand Down Expand Up @@ -41,7 +41,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.12.tar.gz"
"Download URL" = "https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.13.tar.gz"


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


@pytest.mark.parametrize("items, item, other, expected", [
@pytest.mark.parametrize("items, old, new, expected", [
([], None, None, []),
([1], None, None, [1]),
([None], None, None, [None]),
([None], None, 1, [1]),
([1, 2, 3], 2, 4, [1, 4, 3]),
([1, {2: 2}, 3], {2: 2}, 4, [1, 4, 3]),
])
def test__replace(items: list, item: Any, other: Any, expected: list):
def test__replace(items: list, old: Any, new: Any, expected: list):
"""vlist.replace()."""
vlist.replace(items=items, item=item, other=other)
vlist.replace(items=items, old=old, new=new)
assert items == expected


Expand Down
14 changes: 7 additions & 7 deletions vhelpers/vlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ def no_dupl(items: SeqTy) -> ListTy:
return items_


def replace(items: list, item: Any, other: Any) -> None:
def replace(items: list, old: Any, new: Any) -> None:
"""Replace one item with another.
:param items: The list of items where need replace item.
:param item: The item to be replaced.
:param other: The item to replace with.
:param old: The item to be replaced.
:param new: The item to replace with.
:return: None. Update items.
:example:
replace(items=[1, 2, 3], item=2, other=4) -> [1, 4, 3]
replace(items=[1, 2, 3], old=2, new=4) -> [1, 4, 3]
"""
if item in items:
idx = items.index(item)
items[idx] = other
if old in items:
idx = items.index(old)
items[idx] = new


def split(text: str, chars: str = "", ignore: str = "") -> LStr:
Expand Down

0 comments on commit 3c068f4

Please sign in to comment.