lundi 24 février 2020

Random seed for order of elements in Python's Set to List conversion

I was executing some code in a Jupyter notebook and noticed that each time I ran it, the output was different despite not explicitly putting randomness in my program.

I narrowed it down to a line that removes all repeated elements from a list.

l = list(set(l))

I noticed two things:

  • If I re-run the same code in the same Jupyter kernel, I always get the same output for l, but

  • If I open up another notebook, I get a different output.

Is there some kind of hidden random seed that is used for the set -> list conversion for a given kernel? How does it work under the hood, and what would I do if I wanted deterministic output from the above code?




Aucun commentaire:

Enregistrer un commentaire