I have a set of "question" objects that I want to put in a list. There are several hundred of these objects, and each is named in a numbered fashion: question1, question2, etc.
I can build the list by typing them all in:
question_list = [question1, question2, question3, ...
... question500]
but it seems there must be a simple and easy way to build the list, something like:
for i in range(500):
question_list.append(questioni)
Any suggestions?
eval()function doesn't fit best practices you could use it.for i in range(500): question_list.append(eval(f"question{i}"))question1,question2, it's time for a refactor. You will never find a sustainable way forward with that code. It should bequestion = []and thenquestion[0],question[1]Everything will fall into place after that.{'q1':question1,'q2':question2...}