From 68280c69a62b810ebeb9d5ac269753e548429902 Mon Sep 17 00:00:00 2001 From: ekene966 <47493566+ekene966@users.noreply.github.com> Date: Thu, 16 Jul 2020 21:49:05 -0400 Subject: [PATCH] Create Ekene_Uzoegwu.py "help needed" --- .../Python/Ekene_Uzoegwu.py \"help needed\"" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "week-2/Python/Ekene_Uzoegwu.py \"help needed\"" diff --git "a/week-2/Python/Ekene_Uzoegwu.py \"help needed\"" "b/week-2/Python/Ekene_Uzoegwu.py \"help needed\"" new file mode 100644 index 0000000..269e9cf --- /dev/null +++ "b/week-2/Python/Ekene_Uzoegwu.py \"help needed\"" @@ -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') +