def sparse(v):
 for (f, w) in list(v.items()):
  if (w == 0):
   del v[f]
 return v

def sparse ( v ) : for ( f , w ) in list ( v . items ( ) ) : if ( w == 0 ) : del v [ f ] return v
returns the vector with features that have weight 0 removed .