[Solved] How to randomly pick a string from a list, and insert it into a new one? [closed]


From what I can tell, it seems like you want to create a list of a bunch of random features. The way I would personally go about this is by using the random method Choice

Choice allows us to pick a string from a list, then we use a function called .append that lets us include it in another list

from random import choice

Leaves=["(Pointy ","(Rounded ","(Maple ","(Pine ","(Sticks "]
Trunk=["Oak ","Birch ","Maple ","Ash ","Beech ","Spruce "]
Size=["Extra Large)","Large)","Medium)","Small)","Tiny)"]
Tree=[]
NewCombination = []

while len(Tree)<len(Leaves)*len(Trunk)*len(Size):
    NewCombination.append((choice(Leaves)) + (choice(Trunk) + (choice(Size))))

    if Tree != NewCombination:
        Tree=Tree+NewCombination
print(Tree)

I have also made it much easier to see the printed list by including brackets and spaces in your original three lists

solved How to randomly pick a string from a list, and insert it into a new one? [closed]