Is count and counter are same? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is count and counter are same?

3rd May 2020, 1:57 PM
Thirsha
Thirsha - avatar
3 Answers
+ 1
A "Counter" is a container from python module collections, that keeps track of how many times equivalent values are added. Sample code: import collections cnt = collections.Counter() cnt.update('abcdaab') # adding a string cnt.update({'a':1, 'd':5}) # adding a dict print('Counter :', cnt) #result: Counter({'d': 6, 'a': 4, 'b': 2, 'c': 1})
3rd May 2020, 2:21 PM
Lothar
Lothar - avatar
0
It will be better give a sample, Where about you taking in the code..! In python, List has a predefined count function, but I think there is no predefined function like counter in python.. It is user defined as far i know.... It may be from other modules... Edit: ex: L=[1,2,1,1,3 ] print(L.count(1)) #prints 3, =>1's count in list...
3rd May 2020, 2:03 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
- 1
yes๐Ÿคทโ€โ™€๏ธ๐Ÿ˜‚
7th May 2020, 5:12 PM
Shreya