Keys[counts]*vals gives you number of occurrences times the value of the occurrence. Then calculate the product with Times on making a pair with this value and its probability. Finally, Total the list of results from the multiplication.