From 39fda491f8fad91ef910eda461b0e623107756f2 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 29 Apr 2024 03:24:24 +0100 Subject: - Added solutions by Packy Anderson. --- challenge-266/packy-anderson/python/ch-1.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-266/packy-anderson/python/ch-1.py (limited to 'challenge-266/packy-anderson/python/ch-1.py') 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') -- cgit