diff options
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() |
