aboutsummaryrefslogtreecommitdiff
path: root/challenge-266/packy-anderson/python/ch-1.py
blob: ea2c608816d30fb2f900d00522eae841f78b3192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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')