Menu Close

How to shuffle a list of objects with Python?

Sometimes, we want to shuffle a list of objects with Python

In this article, we’ll look at how to shuffle a list of objects with Python.

How to shuffle a list of objects with Python?

To shuffle a list of objects with Python, we can use the shuffle function.

For instance, we write

from random import shuffle

x = [[i] for i in range(10)]
shuffle(x)

to call shuffle with list x to shuffle the items in x in place.

Conclusion

To shuffle a list of objects with Python, we can use the shuffle function.

Posted in Python, Python Answers