aboutsummaryrefslogtreecommitdiff
path: root/challenge-266/packy-anderson/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-266/packy-anderson/python/ch-1.py')
-rw-r--r--challenge-266/packy-anderson/python/ch-1.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-266/packy-anderson/python/ch-1.py b/challenge-266/packy-anderson/python/ch-1.py
new file mode 100644
index 0000000000..ea2c608816
--- /dev/null
+++ b/challenge-266/packy-anderson/python/ch-1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+from collections import Counter
+
+def occursOnce(line):
+ # create a Counter of all words
+ all = Counter(line.split())
+ # create a list of words that occur once in the Counter
+ return [ word for word in list(all) if all[word] == 1 ]
+
+def uncommonWords(line1, line2):
+ return occursOnce(
+ ' '.join(occursOnce(line1) + occursOnce(line2))
+ )
+
+def quoted_comma_join(arr):
+ return "'" + "', '".join(arr) + "'"
+
+def solution(line1, line2):
+ print(f"Input: $line1 = '{line1}'")
+ print(f" $line2 = '{line2}'")
+ uncommon = uncommonWords(line1, line2)
+ print(f'Output: ({quoted_comma_join(uncommon)})')
+
+print('Example 1:')
+solution('Mango is sweet', 'Mango is sour')
+
+print('\nExample 2:')
+solution('Mango Mango', 'Orange')
+
+print('\nExample 3:')
+solution('Mango is Mango', 'Orange is Orange')