Randomly Shuffle List Function

  • Share this:

Code introduction


This function takes a list as an argument and uses the shuffle method from the random library to randomly shuffle the order of elements in the list.


Technology Stack : random

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def shuffle_list(items):
    if not isinstance(items, list):
        raise ValueError("The items must be a list.")
    random.shuffle(items)
    return items                
              
Tags: