Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. from collections import Counter
  2.  
  3. lst = [["Sam", "John", "Alex", "Sam", "Alex"], ["Max", "Sam", "Max"]]
  4.  
  5. print(list(map(Counter, lst)))
  6. # [Counter({'Sam': 2, 'Alex': 2, 'John': 1}), Counter({'Max': 2, 'Sam': 1})]
  7.  
  8. count_list = []
  9. for l in list :
  10. d = {}
  11. for str in l:
  12. if str not in d:
  13. d[str] = l.count(str)
  14. count_list.append(d)
  15.  
  16. count_list = []
  17. for l in list :
  18. d = {}
  19. for str in l:
  20. if str not in d:
  21. d[str] = l.count(str)
  22. count_list.append(d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement