From 5f4fc4231a84f94f57d8a54456b94e8c227dc621 Mon Sep 17 00:00:00 2001 From: ekene966 <47493566+ekene966@users.noreply.github.com> Date: Wed, 22 Jul 2020 18:35:52 -0400 Subject: [PATCH] Create Ekene-Uzoegwu.py --- week-2/Ekene-Uzoegwu.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 week-2/Ekene-Uzoegwu.py diff --git a/week-2/Ekene-Uzoegwu.py b/week-2/Ekene-Uzoegwu.py new file mode 100644 index 0000000..269e9cf --- /dev/null +++ b/week-2/Ekene-Uzoegwu.py @@ -0,0 +1,37 @@ +def longestPalindrome(s): + + # Return if string is empty + if not s: return s + + result = "" + for i in range(len(s)): + j = i + 1 + + while j <= len(s) and len(result) <= len(s[i:]): + + if s[i:j] == s[i:j][::-1] and len(s[i:j]) > len(result): + result = s[i:j] + j += 1 + + return result + +l = "ababad" +print(longestPalindrome(l)) + +print("\n") + + +## String permuation + + +def permutate(str_, Perm_string = ''): + if len(str_) == 0: + print(Perm_string) + else: + for i in range(len(str_)): + y = str_[0:i] + str_[i+1:] + permutate(y, Perm_string + str_[i]) + +print("abb: permuates to ") +permutate('abb') +