Advertisement
Guest User

Untitled

a guest
May 25th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. def get_least_occuring_item_from(array):
  2. dic = {}
  3. leastOccuringItem = None
  4.  
  5. for item in array:
  6. if item in dic:
  7. dic[item] += 1
  8. else:
  9. dic[item] = 1
  10.  
  11. for key in dic:
  12. if leastOccuringItem is None:
  13. leastOccuringItem = key
  14. elif dic[key] < dic[leastOccuringItem]:
  15. leastOccuringItem = key
  16.  
  17. return leastOccuringItem
  18.  
  19. arr = ['apple', 'banana', 'apple', 'pear', 'apple', 'pear', 'banana', 'banana']
  20. print(get_least_occuring_item_from(arr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement