My python3 solution


#1
class Solution:
       
    # O(n) time, O(1) space solution   
    def hammingDistance(self, A):
        pos = {i : 0 for i in range(32)}
        
        for n in A:
            for i, bit in enumerate(bin(n)[-1:1:-1]):
                if bit == '1':
                    pos[i] += 1

            """
                another option here:
                for i, bit in enumerate([n >> i & 1 for i in range(31,-1,-1)]):
                    pos[i] += bit
            """ 
                    
        ans = 2*sum([t*(len(A) - t) for t in pos.values()])            
            
        return ans % 1000000007