mercredi 13 janvier 2016

how to pick random items from a list while avoiding picking the same item in a row

I want to iterate through list with random values. However, I want the item that has been picked to be removed from the list for the next trial, so that I can avoid picking the same item in a row; but it should be added back again after.

please help me on showing that on this simple example. Thank you

import random
    l = [1,2,3,4,5,6,7,8]
    for i in l:
        print random.choice(l)




Aucun commentaire:

Enregistrer un commentaire