I'm having a bit of a problem using classes while using a random in a while loop. The goal is the first time to generate a random string and to use that throughout the lesson. Here are the four lines with the problem.
def run_review(self, key_history):
level = reviewer.ReviewLesson(self.history_list)
if self.counter:
level.shuffled()
self.counter = False
return shuffle
level.review()
level.review_lesson()
from another module
def shuffled(self):
self.shuffled_list = sorted(self.history_list, key=lambda k: random.random())
return self.shuffled_list
def review(self):
for item in self.shuffled_list:
self.word = item+self.word
self.word = self.word*7
return self.word
def review_lesson(self):
word = ''
self.word = word+self.word
return self.word
The issue is after the first block the review_lesson is an empty space since level.review() is not called, however if level.review is called it then becomes another random sequence.
Edit: Made the code a bit more clearer and removed duplicate functions.
self.word + ""is the same as justself.word, If you only want a single value just declare theshuffled_listas a class attribute like in my answeror an instance attribute depending on what you want. Then use it in the method, that way it will only be created once