def dmp_from_dict(f, u, K):
 if (not u):
  return dup_from_dict(f, K)
 if (not f):
  return dmp_zero(u)
 coeffs = {}
 for (monom, coeff) in f.items():
  (head, tail) = (monom[0], monom[1:])
  if (head in coeffs):
   coeffs[head][tail] = coeff
  else:
   coeffs[head] = {tail: coeff}
 (n, v, h) = (max(coeffs.keys()), (u - 1), [])
 for k in range(n, (-1), (-1)):
  coeff = coeffs.get(k)
  if (coeff is not None):
   h.append(dmp_from_dict(coeff, v, K))
  else:
   h.append(dmp_zero(v))
 return dmp_strip(h, u)

def dmp_from_dict ( f , u , K ) : if ( not u ) : return dup_from_dict ( f , K ) if ( not f ) : return dmp_zero ( u ) coeffs = { } for ( monom , coeff ) in f . items ( ) : ( head , tail ) = ( monom [ 0 ] , monom [ 1 : ] ) if ( head in coeffs ) : coeffs [ head ] [ tail ] = coeff else : coeffs [ head ] = { tail : coeff } ( n , v , h ) = ( max ( coeffs . keys ( ) ) , ( u - 1 ) , [ ] ) for k in range ( n , ( - 1 ) , ( - 1 ) ) : coeff = coeffs . get ( k ) if ( coeff is not None ) : h . append ( dmp_from_dict ( coeff , v , K ) ) else : h . append ( dmp_zero ( v ) ) return dmp_strip ( h , u )
create a k[x] polynomial from a dict .