Categories
Python Answers

How to shuffle a list of objects with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *