We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7ec3112 commit 96fa8e6Copy full SHA for 96fa8e6
1 file changed
src/flint/flint_base/flint_base.pyx
@@ -167,11 +167,10 @@ cdef class flint_mpoly_context(flint_elem):
167
def variable_to_index(self, var: Union[int, str]):
168
"""Convert a variable name string or possible index to its index in the context."""
169
if isinstance(var, str):
170
- vars = {x: i for i, x in enumerate(self.names())}
171
- if var not in vars:
+ try:
+ i = self.names().index(var)
172
+ except ValueError:
173
raise ValueError("Variable not in context")
- else:
174
- i = vars[var]
175
elif isinstance(var, int):
176
if not 0 <= var < self.nvars():
177
raise IndexError("Generator index out of range")
0 commit comments