def calc_entropy(string):
 import math
 alphabet = 0
 other = set()
 seen = set()
 lastset = None
 string = to_unicode(string)
 for c in string:
  inset = otherset
  for cset in (lowerset, upperset, numberset, sym1set, sym2set):
   if (c in cset):
    inset = cset
    break
  if (inset not in seen):
   seen.add(inset)
   alphabet += len(inset)
  elif (c not in other):
   alphabet += 1
   other.add(c)
  if (inset is not lastset):
   alphabet += 1
   lastset = cset
 entropy = ((len(string) * math.log(alphabet)) / 0.6931471805599453)
 return round(entropy, 2)

def calc_entropy ( string ) : import math alphabet = 0 other = set ( ) seen = set ( ) lastset = None string = to_unicode ( string ) for c in string : inset = otherset for cset in ( lowerset , upperset , numberset , sym1set , sym2set ) : if ( c in cset ) : inset = cset break if ( inset not in seen ) : seen . add ( inset ) alphabet += len ( inset ) elif ( c not in other ) : alphabet += 1 other . add ( c ) if ( inset is not lastset ) : alphabet += 1 lastset = cset entropy = ( ( len ( string ) * math . log ( alphabet ) ) / 0.6931471805599453 ) return round ( entropy , 2 )
calculates a simple entropy for a given string .