From cf156b74a67191c1a026484029ea088d7bdbda9a Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Fri, 6 Aug 2021 11:53:43 +0530 Subject: [PATCH 1/4] add alternative_string_arrange method --- strings/alternative_string_arrange.py | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 strings/alternative_string_arrange.py diff --git a/strings/alternative_string_arrange.py b/strings/alternative_string_arrange.py new file mode 100644 index 000000000000..5dc99a87e159 --- /dev/null +++ b/strings/alternative_string_arrange.py @@ -0,0 +1,31 @@ +def alternative_string_arrange(first_str: str, second_str: str) -> str: + """ + Return the alternative arrangements of the two strings. + :param first_str: + :param second_str: + :return: String + >>> alternative_string_arrange("ABCD", "XY") + AXBYCD + >>> alternative_string_arrange("XY", "ABCD") + XAYBCD + >>> alternative_string_arrange("AB", "XYZ") + AXBYZ + >>> alternative_string_arrange("ABC", "") + ABC + """ + first_str_length: int = len(first_str) + second_str_length: int = len(second_str) + abs_length: int = ( + first_str_length if first_str_length > second_str_length else second_str_length + ) + li: list = [] + for char_count in range(abs_length): + if char_count < first_str_length: + li.append(first_str[char_count]) + if char_count < second_str_length: + li.append(second_str[char_count]) + return "".join(li) + + +if __name__ == "__main__": + print(alternative_string_arrange("AB", "XYZ"), end=" ") From 4e74e7a6d6f4539d8614b1da7887fcca194e4573 Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Fri, 6 Aug 2021 12:00:41 +0530 Subject: [PATCH 2/4] fix issue --- strings/alternative_string_arrange.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/strings/alternative_string_arrange.py b/strings/alternative_string_arrange.py index 5dc99a87e159..a9400f577074 100644 --- a/strings/alternative_string_arrange.py +++ b/strings/alternative_string_arrange.py @@ -5,13 +5,13 @@ def alternative_string_arrange(first_str: str, second_str: str) -> str: :param second_str: :return: String >>> alternative_string_arrange("ABCD", "XY") - AXBYCD + "AXBYCD" >>> alternative_string_arrange("XY", "ABCD") - XAYBCD + "XAYBCD" >>> alternative_string_arrange("AB", "XYZ") - AXBYZ + "AXBYZ" >>> alternative_string_arrange("ABC", "") - ABC + "ABC" """ first_str_length: int = len(first_str) second_str_length: int = len(second_str) From 334631ad19980ae234acce06028f0c9795e98a87 Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Fri, 6 Aug 2021 12:06:15 +0530 Subject: [PATCH 3/4] fix one more issue --- strings/alternative_string_arrange.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/strings/alternative_string_arrange.py b/strings/alternative_string_arrange.py index a9400f577074..fcf1deb97965 100644 --- a/strings/alternative_string_arrange.py +++ b/strings/alternative_string_arrange.py @@ -5,13 +5,13 @@ def alternative_string_arrange(first_str: str, second_str: str) -> str: :param second_str: :return: String >>> alternative_string_arrange("ABCD", "XY") - "AXBYCD" + 'AXBYCD' >>> alternative_string_arrange("XY", "ABCD") - "XAYBCD" + 'XAYBCD' >>> alternative_string_arrange("AB", "XYZ") - "AXBYZ" + 'AXBYZ' >>> alternative_string_arrange("ABC", "") - "ABC" + 'ABC' """ first_str_length: int = len(first_str) second_str_length: int = len(second_str) From 799f8407947aea27a5588b2a17370011bb14036c Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Fri, 6 Aug 2021 15:36:55 +0530 Subject: [PATCH 4/4] changed the variable name li to output_list --- strings/alternative_string_arrange.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/strings/alternative_string_arrange.py b/strings/alternative_string_arrange.py index fcf1deb97965..d81ddd8a1574 100644 --- a/strings/alternative_string_arrange.py +++ b/strings/alternative_string_arrange.py @@ -18,13 +18,13 @@ def alternative_string_arrange(first_str: str, second_str: str) -> str: abs_length: int = ( first_str_length if first_str_length > second_str_length else second_str_length ) - li: list = [] + output_list: list = [] for char_count in range(abs_length): if char_count < first_str_length: - li.append(first_str[char_count]) + output_list.append(first_str[char_count]) if char_count < second_str_length: - li.append(second_str[char_count]) - return "".join(li) + output_list.append(second_str[char_count]) + return "".join(output_list) if __name__ == "__main__":