Saturday, December 22, 2018

Python Ninja Bootcamp 39-Counter function

Learn Python like a Professional! Take You from 0 to Hero






In this Python lecture, we will learn about the Python Counter function

"Counter is a function within collections module. It returns the occurrence of the elements "


Counter() in python        

Let's see some example-

from collections import Counter


s='aaaaabbbccdddaa'
Counter(s)
>>Counter({'a': 7, 'b': 3, 'c': 2, 'd': 3}) 

l=[1,1,1,2,2,3,3,3,3,3,3,4,4,4,5,5,5,5,2,2]
Counter(l)
>> Counter({1: 3, 2: 4, 3: 6, 4: 3, 5: 4})

t=(1,1,1,2,2,3,3,3,3,3,3)
Counter(t)
>> Counter({1: 3, 2: 2, 3: 6})



EDITS ARE WELCOMED!!

In the next Blog, we will discuss regular expression

https://sngurukuls247.blogspot.com/2018/12/python-ninja-bootcamp-40-regular.html

......................................................................................................................................

Follow the link below to access Free Python Lectures-
https://www.youtube.com/channel/UCENc9qI7_r8KMf6-_1R1xnw

Instagram-
https://www.instagram.com/python.india/

View the Jupyter Notebook for this lecture

Download the Jupyter Notebook for this lecture 




Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com

No comments:

Post a Comment