jeudi 16 février 2017

Python, how to randomly add/append elements from one list to another?

import random
global colours 
global current
colours = ["Red","Yellow","Blue","Green","Orange","White"]
current = []

def randompicker():
    for i in range(4):
        current = random.choice(colours)
randompicker()
print(colours)
print(current)

Hey, so the above program is supposed to randomly add 4 of the elements from the list called colours into the other list named current. I have looked through the forums, but I cannot find help specific to this case.

In short, Is there a quick and efficient way to add 4 random elements from one list straight into another?

Thanks




Aucun commentaire:

Enregistrer un commentaire