def reduceby(key, binop, seq, init=no_default):
 is_no_default = (init == no_default)
 if ((not is_no_default) and (not callable(init))):
  _init = init
  init = (lambda : _init)
 if (not callable(key)):
  key = getter(key)
 d = {}
 for item in seq:
  k = key(item)
  if (k not in d):
   if is_no_default:
    d[k] = item
    continue
   else:
    d[k] = init()
  d[k] = binop(d[k], item)
 return d

def reduceby ( key , binop , seq , init = no_default ) : is_no_default = ( init == no_default ) if ( ( not is_no_default ) and ( not callable ( init ) ) ) : _init = init init = ( lambda : _init ) if ( not callable ( key ) ) : key = getter ( key ) d = { } for item in seq : k = key ( item ) if ( k not in d ) : if is_no_default : d [ k ] = item continue else : d [ k ] = init ( ) d [ k ] = binop ( d [ k ] , item ) return d
perform a simultaneous groupby and reduction the computation: .