Randomly Shuffle a List in Python

  • Share this:

Code introduction


This function takes a list as an argument, then uses the shuffle method from the random module to randomly sort the elements within the list, and returns the sorted list.


Technology Stack : random, list sorting

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def shuffle_list(items):
    random.shuffle(items)
    return items