Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- lst = [["Sam", "John", "Alex", "Sam", "Alex"], ["Max", "Sam", "Max"]]
- print(list(map(Counter, lst)))
- # [Counter({'Sam': 2, 'Alex': 2, 'John': 1}), Counter({'Max': 2, 'Sam': 1})]
- count_list = []
- for l in list :
- d = {}
- for str in l:
- if str not in d:
- d[str] = l.count(str)
- count_list.append(d)
- count_list = []
- for l in list :
- d = {}
- for str in l:
- if str not in d:
- d[str] = l.count(str)
- count_list.append(d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement