Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
[Release] 2024.01.1 (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
shorodilov committed Jan 6, 2024
2 parents 4e056d7 + 7badc13 commit 78e4d6f
Show file tree
Hide file tree
Showing 14 changed files with 387 additions and 282 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Run tox
- name: Run pylint
run: tox -e pylint
- name: Run flake8
run: tox -e flake8
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ To do this use commands:
pip install -r requirements.txt
pip install -e .
Sometimes, you may get an error while installing the source code. Upgrading
``pip`` to the latest version helps for the most of the times.

.. _pip: https://pip.pypa.io/

Code health check
Expand Down
513 changes: 274 additions & 239 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "problem-sets"
version = "2023.10.2"
version = "2024.01.1"
description = "Challenges and solutions for the Python training course"
license = "MIT"
authors = [
Expand Down Expand Up @@ -58,6 +58,7 @@ pytest-cov = "^4.0.0"
mypy = "^1.2.0"
pylint = "^2.17.2"
tox = "^4.4.12"
flake8 = "^7.0.0"

[tool.poetry.scripts]
wtk = "wtk.__main__:run"
Expand Down Expand Up @@ -100,14 +101,14 @@ max-nested-blocks = 3
legacy_tox_ini = """
[tox]
minversion = 4.0
envlist = py39, py310, py311, mypy, pylint
envlist = py39, py310, py311, mypy, pylint, flake8
isolated_build = true
skip_missing_interpreters = true
[gh-actions]
python =
3.9: py39
3.10: py310, mypy, pylint
3.10: py310, mypy, pylint, flake8
3.11: py311
[testenv]
Expand All @@ -128,4 +129,10 @@ deps =
pylint
commands =
pylint src
[testenv:flake8]
deps =
flake8
commands =
flake8 src
"""
29 changes: 1 addition & 28 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
astroid==2.15.8
cachetools==5.3.1
chardet==5.2.0
colorama==0.4.6
coverage==7.3.2
dill==0.3.7
distlib==0.3.7
exceptiongroup==1.1.3
filelock==3.12.4
iniconfig==2.0.0
isort==5.12.0
lazy-object-proxy==1.9.0
mccabe==0.7.0
mypy==1.6.0
mypy-extensions==1.0.0
packaging==23.2
platformdirs==3.11.0
pluggy==1.3.0
pylint==2.17.7
pyproject-api==1.6.1
pytest==7.4.2
pytest-cov==4.1.0
tomli==2.0.1
tomlkit==0.12.1
tox==4.11.3
typing_extensions==4.8.0
virtualenv==20.24.5
wrapt==1.15.0

2 changes: 1 addition & 1 deletion src/atm/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def withdraw_rev(target: int,
"""

raise NotImplementedError # TODO:
raise NotImplementedError


def get_total(values: Iterable[Tuple[int, int]]) -> int:
Expand Down
7 changes: 4 additions & 3 deletions src/calc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

__all__ = [
"get_digits_multiplies",
"get_factorial",
"get_fibonacci_number",
"get_fibonacci_number_nr",
Expand All @@ -13,6 +14,6 @@
"get_squares",
]

from calc.func import (get_factorial, get_fibonacci_number,
get_fibonacci_number_nr, get_square, get_squares,
get_sum_of_strings)
from calc.func import (get_digits_multiplies, get_factorial,
get_fibonacci_number, get_fibonacci_number_nr,
get_square, get_squares, get_sum_of_strings)
15 changes: 15 additions & 0 deletions src/calc/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,18 @@ def get_sum_of_strings(number_1: str, number_2: str, /) -> str:
result += str(carry)

return result[::-1]


def get_digits_multiplies(origin: int) -> List[int]:
"""
Return the digits multiplies for a given number
:param origin: a number to find multiplies
:type origin: int
:return: a list of digits multiplies starting from position 10 ** 1
:rtype: list
"""

return [int(digit) for digit in str(origin)[::-1]]
6 changes: 3 additions & 3 deletions src/quiz/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def load_questions_from_file(source: Union[str, pathlib.Path]) -> Questions:

fieldnames = ["question", "options", "answer"]
questions = []
with open(source) as io_buff:
with open(source) as io_buff: # pylint: disable=W1514
reader = csv.DictReader(io_buff, fieldnames=fieldnames)
for question in reader:
questions.append({
Expand All @@ -64,9 +64,9 @@ def display_question(question: Question) -> None:
"""

print("%s\n" % question["question"])
print("%s\n" % question["question"]) # pylint: disable=C0209
for opt_idx, option in enumerate(question["options"], 1):
print("%d: %s" % (opt_idx, option))
print("%d: %s" % (opt_idx, option)) # pylint: disable=C0209


def gather_answer(question: Question) -> int:
Expand Down
27 changes: 27 additions & 0 deletions src/sequences/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def add_spaces(origin: str) -> str:
return "".join(f" {c}" if c.isupper() else c for c in origin).lstrip()


# pylint: disable=C0103
def get_consecutive_slices(origin: str, n: int) -> List[str]:
"""
Return possible slices of string as a collection consecutive lists
Expand Down Expand Up @@ -301,3 +302,29 @@ def is_vowel(char: str) -> bool:
vowels = "aeiouAEIOU"

return char in vowels


def remove_duplicate_lists(input_list):
"""
Remove duplicate lists from a list of lists.
:param input_list: collection of nested lists
:type input_list: list
:return: List with duplicate lists removed
:rtype: list
"""

seen = set()
result = []

for sublist in input_list:
# Convert each sublist to a tuple to make it hashable
sublist_tuple = tuple(sublist)

if sublist_tuple not in seen:
seen.add(sublist_tuple)
result.append(sublist)

return result
5 changes: 4 additions & 1 deletion src/sorting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@
"heap_sort",
"insertion_sort",
"merge_sort",
"merge_lists",
"quick_sort",
"radix_sort",
"selection_sort",
"shell_sort"
]

from sorting.func import *
from sorting.func import (bubble_sort, bucket_sort, counting_sort, heap_sort,
insertion_sort, merge_lists, merge_sort, quick_sort,
radix_sort, selection_sort, shell_sort)
2 changes: 1 addition & 1 deletion src/wtk/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_fight_result(attack: FightChoice, defence: FightChoice) -> FightResult:

# perform type validation
if not isinstance(attack, FightChoice) or \
not isinstance(defence, FightChoice):
not isinstance(defence, FightChoice):
attack_cls = attack.__class__.__name__
defence_cls = defence.__class__.__name__
raise TypeError(
Expand Down
7 changes: 7 additions & 0 deletions tests/calc/func_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ def test_sum_of_strings_empty():
assert calc.get_sum_of_strings("123", "") == "123"
assert calc.get_sum_of_strings("", "456") == "456"
assert calc.get_sum_of_strings("", "") == "0"


def test_find_digits_multiplies():
assert calc.get_digits_multiplies(123) == [3, 2, 1]
assert calc.get_digits_multiplies(456) == [6, 5, 4]
assert calc.get_digits_multiplies(0) == [0]
assert calc.get_digits_multiplies(2048) == [8, 4, 0, 2]
36 changes: 34 additions & 2 deletions tests/sequences/func_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest

import pytest
from sequences.func import remove_duplicate_lists
import sequences


Expand Down Expand Up @@ -101,3 +101,35 @@ def test_is_vowel():
assert sequences.is_vowel('A') is True
assert sequences.is_vowel('1') is False
assert sequences.is_vowel('@') is False


def test_remove_duplicate_lists():
# Test cases with duplicate lists
input_list1 = [[1, 2, 3], [4, 5], [1, 2, 3], [6, 7]]
expected_output1 = [[1, 2, 3], [4, 5], [6, 7]]

input_list2 = [['a', 'b'], [1, 2], ['a', 'b'], ['c', 'd']]
expected_output2 = [['a', 'b'], [1, 2], ['c', 'd']]

# Test cases without duplicate lists
input_list3 = [[1, 2], [3, 4], [5, 6]]
expected_output3 = [[1, 2], [3, 4], [5, 6]]

input_list4 = [['x', 'y'], ['z'], ['p', 'q'], ['r', 's']]
expected_output4 = [['x', 'y'], ['z'], ['p', 'q'], ['r', 's']]

# Test the function with the test cases
assert remove_duplicate_lists(input_list1) == expected_output1
assert remove_duplicate_lists(input_list2) == expected_output2
assert remove_duplicate_lists(input_list3) == expected_output3
assert remove_duplicate_lists(input_list4) == expected_output4

# Test with an empty list
assert remove_duplicate_lists([]) == []

# Test with a list containing a single empty sublist
input_list5 = [[]]
expected_output5 = [[]]
assert remove_duplicate_lists(input_list5) == expected_output5

# You can add more test cases as needed

0 comments on commit 78e4d6f

Please sign in to comment.