Guest User

Untitled

a guest
Sep 21st, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class Solution(object):
  2. def uncommonFromSentences(self, s1, s2):
  3. """
  4. :type s1: str
  5. :type s2: str
  6. :rtype: List[str]
  7. """
  8. s1Set = set(s1.split(' '))
  9. s2Set = set(s2.split(' '))
  10. s1Set.symmetric_difference_update(s2Set)
  11.  
  12. s1Common = self.getComonWords(s1)
  13. s2Common = self.getComonWords(s2)
  14.  
  15. s1Set.difference_update(s1Common)
  16. s1Set.difference_update(s2Common)
  17.  
  18. return s1Set
  19.  
  20. def getComonWords(self, sentence):
  21. uncommon = set()
  22. common = set()
  23.  
  24. for word in sentence.split(' '):
  25. if word in common:
  26. continue
  27. if word in uncommon:
  28. uncommon.remove(word)
  29. common.add(word)
  30. continue
  31. uncommon.add(word)
  32.  
  33. return common
  34.  
Advertisement
Add Comment
Please, Sign In to add comment