My function is like this:
def func(word1):
for x in index
# lots of stuff
yield from ''.join(word3)
Then I call it later like this:
input3 = next(iter(''.join(func(input2[-x:])) for x in range(len(input1))))
But the results are being sent repeatedly instead of a new random one as it should. The function does not seem to be executed for a while after getting the results. But - after about 5 or so loops (from outside the generator which call the generator as above), an additional randomized result is retrieved from the generator. This was being stacked onto my input in a way like RandWord1RandWord2
. This is why I added input2[-x:]
to make sure I'm only getting the latest result. But the problem is that I want the results to to vary every single time, not after ~5 tries.
I previously had the for
loop that now occurs in the generator as part of my loops from outside of it, and everything worked as I expected. But I had a lot of repeating code because of it so I wanted to define it as a function that could be called instead. I tried searching and I figured next
would be what I needed, but it doesn't force cause the generator to to be executed every time it appears.
Anyone know what could be the problem?
Aucun commentaire:
Enregistrer un commentaire