mardi 4 février 2020

I'm not sure how make a list called a variable name e.g "list1", that changes over each iteration of a for loop [duplicate]

I explain the problem and what i'm trying to achieve in the code.

makes = ['make1', 'make2', 'make3']
for make in makes:
    models = []  # empty list
    if some_condition:
        models.append(some_text)  # after running you get models = ['some_text1', 'some_text2', 'some_text3']
# next I want to store models = ['some_text1', 'some_text2', 'some_text3'] 
# as models0 = ['some_text1', 'some_text2', 'some_text3']
# then I want to store models1 = ['some_text4', 'some_text5', 'some_text6']
# then I want to store models2 = ['some_text7', 'some_text8', 'some_text9']
# since there are 3 makes in makes I want 3 different model variables with changing names, e.g models0, models1, models2. as already stated 
# one way that I have tried to do this is using the following method:
        for number in range (0, 4):
        model + number = [model.replace(' ', '%20') for model in models]  # I also want to strip out the spaces and replace with %20 which is why i'm using .replace
        print(modelnumber)
# I understand my method does not work, how do i amend it so it functions as intended?

the model + number = technique clearly does not work, is there get around?

Aucun commentaire:

Enregistrer un commentaire