From 56fe27f139ec75b98d3855c82bc142e1b6da1e62 Mon Sep 17 00:00:00 2001 From: shellhub Date: Mon, 2 Nov 2020 09:20:16 +0800 Subject: [PATCH 1/7] reverse string --- strings/reverse.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 strings/reverse.py diff --git a/strings/reverse.py b/strings/reverse.py new file mode 100644 index 0000000..fdcaa7c --- /dev/null +++ b/strings/reverse.py @@ -0,0 +1,38 @@ +def reverse(original: str) -> str: + """ + >>> reverse("abc") + 'cba' + >>> reverse('1234') + '4321' + >>> reverse("cba321") + '123abc' + >>> reverse("") + '' + """ + return original[::-1] + + +def reverse2(original: str) -> str: + """ + >>> reverse2("abc") + 'cba' + >>> reverse2('1234') + '4321' + >>> reverse2("cba321") + '123abc' + >>> reverse2("") + '' + """ + original = list(original) + i, j = 0, len(original) - 1 + while i < j: + original[i], original[j] = original[j], original[i], + i += 1 + j -= 1 + return "".join(original) + + +if __name__ == "__main__": + from doctest import testmod + + testmod() From e232c213342af12b6539528e20a0dfd077f2b2d7 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 2 Nov 2020 01:21:24 +0000 Subject: [PATCH 2/7] Formatted with psf/black --- strings/reverse.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/strings/reverse.py b/strings/reverse.py index fdcaa7c..bf19ed8 100644 --- a/strings/reverse.py +++ b/strings/reverse.py @@ -26,7 +26,10 @@ def reverse2(original: str) -> str: original = list(original) i, j = 0, len(original) - 1 while i < j: - original[i], original[j] = original[j], original[i], + original[i], original[j] = ( + original[j], + original[i], + ) i += 1 j -= 1 return "".join(original) From 0d1b3bcc6923dfbebb3a48971277a5c205d6ee13 Mon Sep 17 00:00:00 2001 From: shellhub Date: Mon, 2 Nov 2020 09:33:51 +0800 Subject: [PATCH 3/7] remove whitespace --- strings/remove_whitespace.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 strings/remove_whitespace.py diff --git a/strings/remove_whitespace.py b/strings/remove_whitespace.py new file mode 100644 index 0000000..222ecfc --- /dev/null +++ b/strings/remove_whitespace.py @@ -0,0 +1,32 @@ +def remove_whitespace(original: str) -> str: + """ + >>> remove_whitespace("I Love Python") + 'ILovePython' + >>> remove_whitespace("I Love Python") + 'ILovePython' + >>> remove_whitespace(' I Love Python') + 'ILovePython' + >>> remove_whitespace("") + '' + """ + return "".join(original.split()) + + +def remove_whitespace2(original: str) -> str: + """ + >>> remove_whitespace2("I Love Python") + 'ILovePython' + >>> remove_whitespace2("I Love Python") + 'ILovePython' + >>> remove_whitespace2(' I Love Python') + 'ILovePython' + >>> remove_whitespace2("") + '' + """ + return original.replace(" ", "") + + +if __name__ == '__main__': + from doctest import testmod + + testmod() From e40b7fcd05ea538f0a368f0e21513c5a356a10e4 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 2 Nov 2020 01:34:24 +0000 Subject: [PATCH 4/7] Formatted with psf/black --- strings/remove_whitespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/remove_whitespace.py b/strings/remove_whitespace.py index 222ecfc..11e0761 100644 --- a/strings/remove_whitespace.py +++ b/strings/remove_whitespace.py @@ -26,7 +26,7 @@ def remove_whitespace2(original: str) -> str: return original.replace(" ", "") -if __name__ == '__main__': +if __name__ == "__main__": from doctest import testmod testmod() From 18414aa73fee8c66c8511e519550eafe9f70b842 Mon Sep 17 00:00:00 2001 From: shellhub Date: Mon, 2 Nov 2020 09:50:37 +0800 Subject: [PATCH 5/7] format code --- strings/palindrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/palindrome.py b/strings/palindrome.py index 5c38805..801bbbf 100644 --- a/strings/palindrome.py +++ b/strings/palindrome.py @@ -80,7 +80,7 @@ def is_palindrome_reversion(s: str) -> bool: elif s[0] != s[len(s) - 1]: return False else: - return is_palindrome_reversion(s[1 : len(s) - 1]) + return is_palindrome_reversion(s[1: len(s) - 1]) if __name__ == "__main__": From d5f309b0c90c08016b2d01a8716281331ccd7c23 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 2 Nov 2020 01:51:11 +0000 Subject: [PATCH 6/7] Formatted with psf/black --- strings/palindrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/palindrome.py b/strings/palindrome.py index 801bbbf..5c38805 100644 --- a/strings/palindrome.py +++ b/strings/palindrome.py @@ -80,7 +80,7 @@ def is_palindrome_reversion(s: str) -> bool: elif s[0] != s[len(s) - 1]: return False else: - return is_palindrome_reversion(s[1: len(s) - 1]) + return is_palindrome_reversion(s[1 : len(s) - 1]) if __name__ == "__main__": From 687dc5ba7acf88e0d0f7ceb58441a0195a245c6e Mon Sep 17 00:00:00 2001 From: shellhub Date: Mon, 2 Nov 2020 10:27:12 +0800 Subject: [PATCH 7/7] add contribution --- CONTRIBUTING.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..f03e14c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,27 @@ +# Contributing guidelines + +## Before contributing + +👏👏 Welcome to [examplehub/Python](https://github.com/examplehub/Python) ! Before sending your pull requests. Please make sure that you **read the whole guidelines**. + +## Contributing + +#### How to contribute +1. Fork the project to your github account & clone locally computer. +2. Create an upstream remote and sync your local copy before you branch. +3. Branch for each separate piece of work. +4. Do the work, write good commit messages, and read the `CONTRIBUTING.md`. +5. Push to your origin repository. +6. Create a new PR in GitHub. +7. Waiting to be review by the maintainers. + +#### Code Style + +#### Code Style +* Please follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) Coding Style. +* Single letter variable names are old school so please avoid them unless their life only spans a few lines. +* Expand acronyms because `gcd()` is hard to understand but `greatest_common_divisor()` is not. +* Write `test unit` to test all your functions. +* [More details](https://docs.python.org/3/tutorial/controlflow.html#intermezzo-coding-style) about Code Style. + +### Thanks for your contribution 😊 \ No newline at end of file