fork(2) download
  1. # http://c...content-available-to-author-only...e.com/a/78544/34718
  2.  
  3. import math
  4. def f(s):C=s.count;return-sum(C(x)*math.log2(C(x)/len(s))for x in set(s))
  5.  
  6. print(f("This is a test.")) # 45.094
  7. print(f("00001111")) # 8.000
  8. print(f("cwmfjordbankglyphsvextquiz")) # 122.211
  9. print(f(" ")) # 0.0
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
45.09358392980084
8.0
122.21143267166846
-0.0