lundi 14 janvier 2019

Python: Iterate randomly over multiple lists sequentielly

Suppose I have three classes of objects and three lists containing multiple instances of the corresponding class. I want each object to perform a similar action n times. I can do this in a fixed order with itertools.chain (iterate over every object in first list n times, do it for the second list, etc.).

My problem is, I have to do it by random. This means: pick one object by random from one of the three lists picked by random, perform the individual action and do this till all actions are done.

So far the possible solutions I visualize are very cumbersome, maybe you can show me the pythonic way to do this...

Thanks!




Aucun commentaire:

Enregistrer un commentaire