- self._coefficients = OrderedDict()
- for symbol, coefficient in sorted(coefficients,
- key=lambda item: item[0].name):
- if isinstance(coefficient, Rational):
- coefficient = coefficient.constant
- if not isinstance(coefficient, numbers.Rational):
- raise TypeError('coefficients must be rational numbers '
- 'or Rational instances')
- self._coefficients[symbol] = coefficient
- if isinstance(constant, Rational):
- constant = constant.constant
- if not isinstance(constant, numbers.Rational):
- raise TypeError('constant must be a rational number '
- 'or a Rational instance')
- self._constant = constant