From 241dd5096f1cfc82998e6626cf4fe4c349082841 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Wed, 17 Sep 2025 04:24:03 +0000 Subject: [PATCH 1/5] [Sync Iteration] python/sublist/1 --- solutions/python/sublist/1/sublist.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 solutions/python/sublist/1/sublist.py diff --git a/solutions/python/sublist/1/sublist.py b/solutions/python/sublist/1/sublist.py new file mode 100644 index 0000000..33d8f6c --- /dev/null +++ b/solutions/python/sublist/1/sublist.py @@ -0,0 +1,23 @@ +""" +This exercise stub and the test suite contain several enumerated constants. + +Enumerated constants can be done with a NAME assigned to an arbitrary, +but unique value. An integer is traditionally used because it’s memory +efficient. + +It is a common practice to export both constants and functions that work with +those constants (ex. the constants in the os, subprocess and re modules). + +You can learn more here: https://en.wikipedia.org/wiki/Enumerated_type +""" + +# Possible sublist categories. +# Change the values as you see fit. +SUBLIST = None +SUPERLIST = None +EQUAL = None +UNEQUAL = None + + +def sublist(list_one, list_two): + pass From 35db05a9bd0fef290dbe228e9adcaa26c1e830b3 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 22 Sep 2025 12:27:22 -0700 Subject: [PATCH 2/5] Update sublist.py --- sublist/sublist.py | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/sublist/sublist.py b/sublist/sublist.py index 33d8f6c..e70e7dc 100644 --- a/sublist/sublist.py +++ b/sublist/sublist.py @@ -13,11 +13,45 @@ # Possible sublist categories. # Change the values as you see fit. -SUBLIST = None -SUPERLIST = None -EQUAL = None -UNEQUAL = None +SUBLIST = "SUBLIST" +SUPERLIST = "SUPERLIST" +EQUAL = "EQUAL" +UNEQUAL = "UNEQUAL" -def sublist(list_one, list_two): - pass +def sublist(list_one: list, list_two: list) -> str: + """ + Classify the relationship between two lists. + + Determines whether ``list_one`` and ``list_two`` are equal, or whether one + is a contiguous sublist of the other, and returns the appropriate constant. + + :param list_one: First list to compare. + :type list_one: list + :param list_two: Second list to compare. + :type list_two: list + :returns: One of ``EQUAL``, ``SUBLIST``, ``SUPERLIST``, or ``UNEQUAL``. + :rtype: str + """ + if list_one is list_two or list_one == list_two: + return EQUAL + + if len(list_one) == len(list_two) and not ( + list_one is list_two or list_one == list_two + ): + return UNEQUAL + + l1: str = ",".join(str(i) for i in list_one) + l2: str = ",".join(str(i) for i in list_two) + + if len(l1) > len(l2): + for i in range(0, len(l1) - len(l2) + 1): + if l1[i:].startswith(l2): + return SUPERLIST + + if len(l2) > len(l1): + for i in range(0, len(l2) - len(l1) + 1): + if l2[i:].startswith(l1): + return SUBLIST + + return UNEQUAL From 01578413b453ee28ede37cf49e7f46ebbd72ebcc Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 22 Sep 2025 12:38:02 -0700 Subject: [PATCH 3/5] Sublist --- sublist/sublist.py | 12 +++++------- sublist/sublist_test.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/sublist/sublist.py b/sublist/sublist.py index e70e7dc..dedd59c 100644 --- a/sublist/sublist.py +++ b/sublist/sublist.py @@ -37,7 +37,7 @@ def sublist(list_one: list, list_two: list) -> str: return EQUAL if len(list_one) == len(list_two) and not ( - list_one is list_two or list_one == list_two + list_one is list_two or list_one == list_two ): return UNEQUAL @@ -45,13 +45,11 @@ def sublist(list_one: list, list_two: list) -> str: l2: str = ",".join(str(i) for i in list_two) if len(l1) > len(l2): - for i in range(0, len(l1) - len(l2) + 1): - if l1[i:].startswith(l2): - return SUPERLIST + if l2 in l1: + return SUPERLIST if len(l2) > len(l1): - for i in range(0, len(l2) - len(l1) + 1): - if l2[i:].startswith(l1): - return SUBLIST + if l1 in l2: + return SUBLIST return UNEQUAL diff --git a/sublist/sublist_test.py b/sublist/sublist_test.py index eed1c90..920aeee 100644 --- a/sublist/sublist_test.py +++ b/sublist/sublist_test.py @@ -1,4 +1,4 @@ -# pylint: disable=C0301 +# pylint: disable=C0301, C0116 # These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/sublist/canonical-data.json # File last updated on 2023-07-19 From 88c72d920759dc589536c41507ba1075c445621b Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 22 Sep 2025 12:47:13 -0700 Subject: [PATCH 4/5] Code refactoring --- sublist/sublist.py | 15 ++++++++------- sublist/sublist_test.py | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sublist/sublist.py b/sublist/sublist.py index dedd59c..17a6e70 100644 --- a/sublist/sublist.py +++ b/sublist/sublist.py @@ -33,22 +33,23 @@ def sublist(list_one: list, list_two: list) -> str: :returns: One of ``EQUAL``, ``SUBLIST``, ``SUPERLIST``, or ``UNEQUAL``. :rtype: str """ - if list_one is list_two or list_one == list_two: - return EQUAL - if len(list_one) == len(list_two) and not ( - list_one is list_two or list_one == list_two - ): + len1: int = len(list_one) + len2: int = len(list_two) + + if len1 == len2: + if list_one is list_two or list_one == list_two: + return EQUAL return UNEQUAL l1: str = ",".join(str(i) for i in list_one) l2: str = ",".join(str(i) for i in list_two) - if len(l1) > len(l2): + if len1 > len2: if l2 in l1: return SUPERLIST - if len(l2) > len(l1): + if len2 > len1: if l1 in l2: return SUBLIST diff --git a/sublist/sublist_test.py b/sublist/sublist_test.py index 920aeee..2ca0cb9 100644 --- a/sublist/sublist_test.py +++ b/sublist/sublist_test.py @@ -1,4 +1,4 @@ -# pylint: disable=C0301, C0116 +# pylint: disable=C0301, C0114, C0115, C0116, R0904 # These tests are auto-generated with test data from: # https://github.com/exercism/problem-specifications/tree/main/exercises/sublist/canonical-data.json # File last updated on 2023-07-19 From 5ea176febfe789980a0b7c78cd5940107f8fedf6 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 22 Sep 2025 12:48:59 -0700 Subject: [PATCH 5/5] Update sublist.py --- sublist/sublist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sublist/sublist.py b/sublist/sublist.py index 17a6e70..ca9854c 100644 --- a/sublist/sublist.py +++ b/sublist/sublist.py @@ -38,7 +38,7 @@ def sublist(list_one: list, list_two: list) -> str: len2: int = len(list_two) if len1 == len2: - if list_one is list_two or list_one == list_two: + if list_one == list_two: return EQUAL return UNEQUAL