From d3e1dafec5939cc9ee99b7cf89323b0c6bef63bb Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Sun, 17 Oct 2021 09:58:40 +0530 Subject: [PATCH 01/11] Create join.py Because we have a split.py --- strings/join.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 strings/join.py diff --git a/strings/join.py b/strings/join.py new file mode 100644 index 000000000000..4a7c3b77324f --- /dev/null +++ b/strings/join.py @@ -0,0 +1,33 @@ +""" +Program to join a list of strings with a given separator +""" + + +def join(separated: list, separator: str = "") -> str: + """ + test_list = ["a", "b", "c", "d"] + >>> join(test_list) + abcd + >>> join(test_list, "#") + a#b#c#d + >>> join(test_list[0], "#") + a + >>> join(["You", "are", "amazing!"], " ") + You are amazing! + >>> join(["a", "b", "c", 1], "#") + Traceback (most recent call last): + ... + Exception: join() accepts only strings to be joined + """ + joined = "" + for word_or_phrase in separated: + if not isinstance(word_or_phrase, str): + raise Exception("join() accepts only strings to be joined") + joined += word_or_phrase + separator + return joined.strip(separator) + + +if "__name__" == "__main__": + from doctest import testmod + + testmod() From b84d8088d039b11e4f0a2053765bfac6a0956ec0 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Sun, 17 Oct 2021 10:03:34 +0530 Subject: [PATCH 02/11] Update join.py --- strings/join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/join.py b/strings/join.py index 4a7c3b77324f..d34bfc87f981 100644 --- a/strings/join.py +++ b/strings/join.py @@ -29,5 +29,5 @@ def join(separated: list, separator: str = "") -> str: if "__name__" == "__main__": from doctest import testmod - + testmod() From 73435f2102c5519e4a502ca836ea1d66f80de46b Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Sun, 17 Oct 2021 10:08:03 +0530 Subject: [PATCH 03/11] Update join.py --- strings/join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/join.py b/strings/join.py index d34bfc87f981..1e0230f61cf1 100644 --- a/strings/join.py +++ b/strings/join.py @@ -29,5 +29,5 @@ def join(separated: list, separator: str = "") -> str: if "__name__" == "__main__": from doctest import testmod - + testmod() From 932cae7a9d15bce1d13e77f46e2afdd248efd661 Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Sun, 17 Oct 2021 12:14:38 +0530 Subject: [PATCH 04/11] Update join.py --- strings/join.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/join.py b/strings/join.py index 1e0230f61cf1..62c8a524e007 100644 --- a/strings/join.py +++ b/strings/join.py @@ -10,6 +10,8 @@ def join(separated: list, separator: str = "") -> str: abcd >>> join(test_list, "#") a#b#c#d + >>> join(test_list[:2], "#") + a#b >>> join(test_list[0], "#") a >>> join(["You", "are", "amazing!"], " ") From c483b7b1a1e7cd6fb3b9d9000c83472b9ed769fd Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Sun, 17 Oct 2021 12:21:00 +0530 Subject: [PATCH 05/11] Update join.py --- strings/join.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/strings/join.py b/strings/join.py index 62c8a524e007..f735bd44c003 100644 --- a/strings/join.py +++ b/strings/join.py @@ -5,14 +5,11 @@ def join(separated: list, separator: str = "") -> str: """ - test_list = ["a", "b", "c", "d"] - >>> join(test_list) + >>> join(["a", "b", "c", "d"]) abcd - >>> join(test_list, "#") + >>> join(["a", "b", "c", "d"], "#") a#b#c#d - >>> join(test_list[:2], "#") - a#b - >>> join(test_list[0], "#") + >>> join("a", "#") a >>> join(["You", "are", "amazing!"], " ") You are amazing! From 553d767404946a45237fed9f84e2f2d03f0cec9b Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Sun, 17 Oct 2021 12:25:24 +0530 Subject: [PATCH 06/11] Update join.py --- strings/join.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/strings/join.py b/strings/join.py index f735bd44c003..8eba369eb598 100644 --- a/strings/join.py +++ b/strings/join.py @@ -6,13 +6,13 @@ def join(separated: list, separator: str = "") -> str: """ >>> join(["a", "b", "c", "d"]) - abcd + 'abcd' >>> join(["a", "b", "c", "d"], "#") - a#b#c#d + 'a#b#c#d' >>> join("a", "#") - a + 'a' >>> join(["You", "are", "amazing!"], " ") - You are amazing! + 'You are amazing!' >>> join(["a", "b", "c", 1], "#") Traceback (most recent call last): ... From d11ab8291e485ea40764d29f5bf8bf5ce9ff32fa Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 18 Oct 2021 14:17:05 +0530 Subject: [PATCH 07/11] Update strings/join.py Co-authored-by: John Law --- strings/join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/join.py b/strings/join.py index 8eba369eb598..72ecb5194151 100644 --- a/strings/join.py +++ b/strings/join.py @@ -3,7 +3,7 @@ """ -def join(separated: list, separator: str = "") -> str: +def join(separator: str, separated: list) -> str: """ >>> join(["a", "b", "c", "d"]) 'abcd' From ce2f37d3d3a3d2f13915be559e7663bb07a4446b Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 18 Oct 2021 14:25:36 +0530 Subject: [PATCH 08/11] Update join.py --- strings/join.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/strings/join.py b/strings/join.py index 72ecb5194151..98f02f1b2b67 100644 --- a/strings/join.py +++ b/strings/join.py @@ -6,7 +6,9 @@ def join(separator: str, separated: list) -> str: """ >>> join(["a", "b", "c", "d"]) - 'abcd' + Traceback (most recent call last): + ... + TypeError: join() missing 1 required positional argument: 'separated' >>> join(["a", "b", "c", "d"], "#") 'a#b#c#d' >>> join("a", "#") From e803a8548302495767c103d0ea233f0bbc46578e Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 18 Oct 2021 14:30:32 +0530 Subject: [PATCH 09/11] Update join.py --- strings/join.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/strings/join.py b/strings/join.py index 98f02f1b2b67..d728b063a121 100644 --- a/strings/join.py +++ b/strings/join.py @@ -3,12 +3,10 @@ """ -def join(separator: str, separated: list) -> str: +def join(separator: str = "", separated: list) -> str: """ >>> join(["a", "b", "c", "d"]) - Traceback (most recent call last): - ... - TypeError: join() missing 1 required positional argument: 'separated' + 'abcd' >>> join(["a", "b", "c", "d"], "#") 'a#b#c#d' >>> join("a", "#") From 7c73af813f2ecf592b7e76f32d228d1c5cb4128a Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 18 Oct 2021 14:34:20 +0530 Subject: [PATCH 10/11] Update join.py --- strings/join.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/strings/join.py b/strings/join.py index d728b063a121..a8b7d6c06b8e 100644 --- a/strings/join.py +++ b/strings/join.py @@ -5,15 +5,15 @@ def join(separator: str = "", separated: list) -> str: """ - >>> join(["a", "b", "c", "d"]) + >>> join(separated = ["a", "b", "c", "d"]) 'abcd' - >>> join(["a", "b", "c", "d"], "#") + >>> join("#", ["a", "b", "c", "d"]) 'a#b#c#d' - >>> join("a", "#") + >>> join("#", "a") 'a' - >>> join(["You", "are", "amazing!"], " ") + >>> join(" ", ["You", "are", "amazing!"]) 'You are amazing!' - >>> join(["a", "b", "c", 1], "#") + >>> join("#", ["a", "b", "c", 1]) Traceback (most recent call last): ... Exception: join() accepts only strings to be joined From f5ada9a16f0289766d6448de2b42703baef1613b Mon Sep 17 00:00:00 2001 From: Rohan R Bharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Mon, 18 Oct 2021 14:37:45 +0530 Subject: [PATCH 11/11] Update join.py --- strings/join.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/join.py b/strings/join.py index a8b7d6c06b8e..0cb88b76065d 100644 --- a/strings/join.py +++ b/strings/join.py @@ -3,9 +3,9 @@ """ -def join(separator: str = "", separated: list) -> str: +def join(separator: str, separated: list) -> str: """ - >>> join(separated = ["a", "b", "c", "d"]) + >>> join("", ["a", "b", "c", "d"]) 'abcd' >>> join("#", ["a", "b", "c", "d"]) 'a#b#c#d'