diff options
Diffstat (limited to 'challenge-145/lubos-kolouch/python/ch-2.py')
| -rw-r--r-- | challenge-145/lubos-kolouch/python/ch-2.py | 21 |
1 files changed, 21 insertions, 0 deletions
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'] |
