Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. //Previous code
  2. a = list(map(int, raw_input().split()))
  3. for i in a:
  4. if a.count(i) == 1:
  5. print i
  6. break
  7.  
  8.  
  9. // Current code
  10. from collections import Counter
  11. a = list(map(int, raw_input().split()))
  12. b = Counter(a)
  13. onlies = [k for k,v in b if v == 1]
  14. print onlies
  15.  
  16.  
  17. # one way using sets
  18. present = set()
  19. morelies = set()
  20.  
  21. for i in a:
  22. if i in present:
  23. morelies.add(i)
  24. else:
  25. present.add(i)
  26.  
  27. onlies = present - morelies
  28. print(onlies)
  29.  
  30.  
  31. # another way using sets
  32. onlies = set()
  33. morelies = set()
  34.  
  35. for i in a:
  36. if i in morelies:
  37. pass
  38. elif i in onlies:
  39. morelies.add(i)
  40. onlies.remove(i)
  41. else:
  42. onlies.add(i)
  43.  
  44. print(onlies)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement