How can I get a count of all the string elements from the given list?
Var1 = ['2019-11-22', '2019-11-22', '2019-11-20']
Desired Output:
2019-11-22 : count(2)
2019-11-20 : count(1)
How can I get a count of all the string elements from the given list?
Var1 = ['2019-11-22', '2019-11-22', '2019-11-20']
Desired Output:
2019-11-22 : count(2)
2019-11-20 : count(1)
That's what a counter is for.
from collections import Counter
Var1 = ['2019-11-22', '2019-11-22', '2019-11-20']
counts = Counter(Var1)
from collections import Counter
var1 = ['2019-11-22', '2019-11-22', '2019-11-20']
for i, c in Counter(var1).items():
print(f"{i}: count({c})")