diff options
| author | Packy Anderson <PackyAnderson@gmail.com> | 2024-05-06 23:41:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-06 23:41:04 -0400 |
| commit | 8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b (patch) | |
| tree | 4cc9a6443382d2a32208246c481cd566b6ea0142 /challenge-266/pokgopun/python/ch-1.py | |
| parent | e4a2c66b30346606d347ecc4a08b83b733797d2a (diff) | |
| parent | c1756b0e7aed0ad70fa63feb2565c69215c9d426 (diff) | |
| download | perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.gz perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.bz2 perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.zip | |
Merge branch 'manwar:master' into challenge-268
Diffstat (limited to 'challenge-266/pokgopun/python/ch-1.py')
| -rw-r--r-- | challenge-266/pokgopun/python/ch-1.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/challenge-266/pokgopun/python/ch-1.py b/challenge-266/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..96addf3d91 --- /dev/null +++ b/challenge-266/pokgopun/python/ch-1.py @@ -0,0 +1,57 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-266/ +""" + +Task 1: Uncommon Words + +Submitted by: [41]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given two sentences, $line1 and $line2. + + Write a script to find all uncommmon words in any order in the given + two sentences. Return ('') if none found. + + A word is uncommon if it appears exactly once in one of the + sentences and doesn’t appear in other sentence. + +Example 1 + +Input: $line1 = 'Mango is sweet' + $line2 = 'Mango is sour' +Output: ('sweet', 'sour') + +Example 2 + +Input: $line1 = 'Mango Mango' + $line2 = 'Orange' +Output: ('Orange') + +Example 3 + +Input: $line1 = 'Mango is Mango' + $line2 = 'Orange is Orange' +Output: ('') + +Task 2: X Matrix +""" +### solution by pokgopun@gmail.com + +def uncommonWords(line1, line2): + words = f'{line1} {line2}'.split() + return tuple( + w for w in words if words.count(w)==1 + ) or ('',) + + +import unittest + +class TestUncommonWords(unittest.TestCase): + def test(self): + for (line1,line2), ans in { + ('Mango is sweet','Mango is sour'): ('sweet', 'sour'), + ('Mango Mango','Orange'): ('Orange',), + ('Mango is Mango','Orange is Orange'): ('',), + }.items(): + self.assertEqual(uncommonWords(line1,line2),ans) + +unittest.main() |
