Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter as cr
- x = [1, 5, 'a', 'b', 'c', 1, 'b', 'a', 'c', 'c', 1, 1, 1]
- words = cr(x) # which element how much time
- #--------------------------------
- c = cr() # intialize counter
- c.update('xyzzzzxy') # update c
- #--------------------------------
- c1 = cr('abcdaab')
- for l in 'abcde':
- print('{} : {} '.format(l, c1[l]), end=' ')
- print('\n')
- # element:
- # -------------
- c2 = cr('extreme')
- c2['z'] = 0
- # print(c2)
- # print(list(c2.elements())) # only key elements
- # get most common
- #---------------------
- print('\n')
- dummyList = [1, 11, 1, 2, 4, 8, 'a', 'x', 'w',
- 5, 9, 'o', 'o', 10, 11, 11, 1, 1]
- c3 = cr()
- c3.update(dummyList)
- print(c3.most_common(3)) # most common words
Advertisement
Add Comment
Please, Sign In to add comment