mardi 24 octobre 2017

Python random sample with exception

I'm attempting to create a sample of myList with the exception of i_.

My Attempt:

i_ = 'd'

myList = ['a','b','c','d','e']

myList = random.sample(myList, 3)

Although the above sample works fine, there is still a chance that i_ is removed from myList.

I would like to create a sample without the value of i_ being removed.

Desired Output:

Any list output containing 3 items and i_, e.g:

['a','d','e']




Aucun commentaire:

Enregistrer un commentaire