aboutsummaryrefslogtreecommitdiff
path: root/challenge-266/packy-anderson/python/ch-1.py
diff options
context:
space:
mode:
authorPacky Anderson <packy@cpan.org>2024-04-24 01:10:11 -0400
committerPacky Anderson <packy@cpan.org>2024-04-24 01:10:11 -0400
commitd8ae12d13bdb74b6f9ce88dd3c8732dfe3984e18 (patch)
tree05472ced28aef27e3c1a6f6983dfd5ddd151b007 /challenge-266/packy-anderson/python/ch-1.py
parent25c88efc3e83fc333e98da6a0157e1853be61044 (diff)
downloadperlweeklychallenge-club-d8ae12d13bdb74b6f9ce88dd3c8732dfe3984e18.tar.gz
perlweeklychallenge-club-d8ae12d13bdb74b6f9ce88dd3c8732dfe3984e18.tar.bz2
perlweeklychallenge-club-d8ae12d13bdb74b6f9ce88dd3c8732dfe3984e18.zip
Challenge 266 solutions by Packy Anderson
* Raku that looks like Perl * Perl * Python that looks like Perl 1 Blog post
Diffstat (limited to 'challenge-266/packy-anderson/python/ch-1.py')
-rwxr-xr-xchallenge-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 100755
index 0000000000..017d8a6c12
--- /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') \ No newline at end of file