I'm trying to make a math expression game in python, but I need my MandaExp method to return an expression every time it's called. In this method I have a list called explist, where several expressions are organized according to the selection of difficulty of the user. Searching for some things but the way it is it only returns a list with the indices, that is, a list that goes from 0 to 430. Here is the part of the code:
class MotorDoJogoSP(object):
import operator
def MandaExp(self, dif):
Dificultador.Sort = Dicio[dif]
expr = Dificultador().Sort()
explist = [operator.attrgetter('expressao')(x) for x in expr]
resplist = [operator.attrgetter('resposta')(x) for x in expr]
for e in range(len(explist)):
yield e
If you do print list(MotorDoJogoSP().MandaExp(dif))
it returns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ..., 430]
The expected output was the elements of explist, each time it was called the method would output an element from the list, Example: 36 + 0, 30/0, ...