jeudi 11 juin 2020

Algorithim to access two random elements from a list, store them in a variable and delete the elements from the original list in Python 3.x?

I have a list , that so far has 4 elements . I can use the random.sample command to pick 2 elements at random

teamslist = "apple" , "banana" , "orange", "clementines"
teamrandom = random.sample(teamslist, k = 2)

Is there anyway for the randomly picked elements stored in teamrandom , to be removed from list "teamlist" , so that only the remaining 2 strings are left in the list?

This way, when the command is run again, it only picks the 2 remaining elements from the list?

No element should be chosen more than once




Aucun commentaire:

Enregistrer un commentaire