vendredi 21 octobre 2016

How to get random.sample() from deque in Python 3?

I have a collections.deque() of tuples from which I want to draw random samples. In Python 2.7, I can use batch = random.sample(my_deque, batch_size).

But in Python 3.4 this raises TypeError: Population must be a sequence or set. For dicts, use list(d).

What's the best workaround, or recommended way to sample efficiently from a deque in Python 3?




Aucun commentaire:

Enregistrer un commentaire