]> CRI, Mines Paris - PSL - linpy.git/blobdiff - linpy/linexprs.py
Simplify LinExpr.coefficients()
[linpy.git] / linpy / linexprs.py
index b2cec53b303a1df571cc9b2a5625a432308acd56..ab5d344c8006d9394500ec74d741d2692db5e34d 100644 (file)
@@ -122,7 +122,7 @@ class LinExpr:
         """
         if not isinstance(symbol, Symbol):
             raise TypeError('symbol must be a Symbol instance')
         """
         if not isinstance(symbol, Symbol):
             raise TypeError('symbol must be a Symbol instance')
-        return self._coefficients.get(symbol, 0)
+        return self._coefficients.get(symbol, Fraction(0))
 
     __getitem__ = coefficient
 
 
     __getitem__ = coefficient
 
@@ -131,8 +131,7 @@ class LinExpr:
         Iterate over the pairs (symbol, value) of linear terms in the
         expression. The constant term is ignored.
         """
         Iterate over the pairs (symbol, value) of linear terms in the
         expression. The constant term is ignored.
         """
-        for symbol, coefficient in self._coefficients.items():
-            yield symbol, coefficient
+        yield from self._coefficients.items()
 
     @property
     def constant(self):
 
     @property
     def constant(self):