I am trying to build a list by picking random elements from another list with no duplicates. Think shuffling a pack of cards. I could obviously write some unpythonic code for this, which I dont want to.
So here is what I am trying to do:
new = [deck[i] where 0<(i = some_rand_int)<51 if new.count(deck[i]) == 0]
Is there a way to do this?
Use
random.sample:Try this:
To shuffle the entire list use
random.shuffle:Not really. A list comphrension preserves the order of the elements, but allows you to project them or filter them. Shuffling is not a projection or a filter.