Count set bits in Python

Any built in function in Python to count number of set bits

We can solve this problem in Python using List comprehension. Approach is simple,

Convert given number into it’s binary representation using bin(number) function.
Now separate out all 1’s from binary representation of given number and print length of list of 1’s.
Have a look here :