From 393d8f7b2cc5cb6fa63fd185b730a61173e452a4 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sat, 8 Jul 2023 12:33:49 +0200 Subject: feat(challenge-145/lubos-kolouch/perl,python/): Challenge 145 LK Perl Python --- challenge-145/lubos-kolouch/python/ch-2.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 challenge-145/lubos-kolouch/python/ch-2.py (limited to 'challenge-145/lubos-kolouch/python/ch-2.py') diff --git a/challenge-145/lubos-kolouch/python/ch-2.py b/challenge-145/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..7a9584b223 --- /dev/null +++ b/challenge-145/lubos-kolouch/python/ch-2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +def palindromic_tree(s): + result = [] + for i in range(len(s)): + for j in range(i + 1, len(s) + 1): + substring = s[i:j] + if substring == substring[::-1]: + result.append(substring) + return result + + +s = "redivider" +print( + palindromic_tree(s) +) # Output: ['r', 'redivider', 'e', 'edivide', 'd', 'divid', 'i', 'ivi', 'v'] + +s = "deific" +print(palindromic_tree(s)) # Output: ['d', 'e', 'i', 'ifi', 'f', 'c'] -- cgit