diff options
| author | Myoungjin JEON <jeongoon@gmail.com> | 2020-10-15 00:04:11 +1100 |
|---|---|---|
| committer | Myoungjin JEON <jeongoon@gmail.com> | 2020-10-15 00:04:11 +1100 |
| commit | dd71532a73981ec613c8c61d99fa4bbd3f3fd79c (patch) | |
| tree | 70b1b5c1613f51461bb27f6b4aa49ba8b5efa78e /challenge-081/lubos-kolouch/python/ch-1.py | |
| parent | 99053d27c19ab6baee10484e8de730527333ddde (diff) | |
| parent | a86e289ff2bb02e7c579be9175c92f2667168a28 (diff) | |
| download | perlweeklychallenge-club-dd71532a73981ec613c8c61d99fa4bbd3f3fd79c.tar.gz perlweeklychallenge-club-dd71532a73981ec613c8c61d99fa4bbd3f3fd79c.tar.bz2 perlweeklychallenge-club-dd71532a73981ec613c8c61d99fa4bbd3f3fd79c.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-081/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-081/lubos-kolouch/python/ch-1.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-081/lubos-kolouch/python/ch-1.py b/challenge-081/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..e3b1b080ce --- /dev/null +++ b/challenge-081/lubos-kolouch/python/ch-1.py @@ -0,0 +1,36 @@ +#!/bin/env python +""" =============================================================================== +# +# FILE: ch-1.py +# +# USAGE: ./ch-1.py +# +# DESCRIPTION: Perl Weekly Challenge 081 +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/ +# Task 1 - Common base string +# +# AUTHOR: Lubos Kolouch +# CREATED: 10/09/2020 10:43:10 AM +#=============================================================================== +""" +import re + + +def get_common_strings(str1, str2): + """ Find and return the common strings """ + + result = [] + res1 = re.match(r'(.*)\1+', str1) + + result.append(res1.group(1)) + + res2 = re.match(r'(.*)\1+', str2) + if res1.group(1) != res2.group(1): + result.append(res2.group(1)) + + return result + + +assert get_common_strings('abcdabcd', 'abcdabcdabcdabcd') == ['abcd','abcdabcd'] +assert get_common_strings('aaa', 'aa') == ['a'] +assert get_common_strings('abc', 'aa') == ['','a'] |
