mercredi 23 septembre 2015

Randomly Selcting non zero element from array

I have a list A=[7,11,13] and size=3. I want to randomly select a position in A and subtract random number from it till it becomes 0. Problem is every time I select a random index by index=random.choice[0,1,2] I have to manually check whether value in A corresponding to that index is zero or not. Is there a way in python that automatically gives random index for no zero elements in list?




Aucun commentaire:

Enregistrer un commentaire