jeudi 4 août 2022

Shuffle a dictionary and list in unison?

I have a dictionary and list with same rows. I would like to shuffle the dictionary and list in unison that is with the same random seed.

test_dict = {3.0: deque([0.897, 24, 45]),
             2.0: deque([0.0, 0.5, 56]),
             9.0: deque([3.4, 0.9, 0.5])}

test_list = [deque([0.897, 24, 45]),
             deque([0.0, 0.5, 56]),
             deque([3.4, 0.9, 0.5])]

Is there a way to shuffle these two in the same order?

I tried the shuffle function from:

from random import shuffle
from sklearn.utils import shuffle

Both ended up giving an error. Is there a easier way to do this?

Edit: Since the values in the dictionary and elements in the list are same, I was wondering if we could shuffle the list and reassign them to the keys in the dictionary.




Aucun commentaire:

Enregistrer un commentaire