Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter, defaultdict
- li = [1, 2, 4, 3, 4, 4, 5, 6, 6, 7, 8]
- print(Counter(li)) # Counter({4: 3, 6: 2, 1: 1, 2: 1, 3: 1, 5: 1, 7: 1, 8: 1})
- dict = defaultdict(int, {'a': 1, 'b': 2, 'c': 4})
- print(dict['d']) # 0
- dict2 = defaultdict(lambda: "value does not exist", {'a': 1, 'b': 2})
- print(dict2['d']) # value does not exist
Add Comment
Please, Sign In to add comment