In-Place Random List Shuffling Function

  • Share this:

Code introduction


This function takes a list as an argument and randomly shuffles the order of the elements within the list in place.


Technology Stack : random

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def shuffle_list(items):
    """
    Randomly shuffle the elements of the list in place.

    Parameters:
    items (list): The list to be shuffled.

    Returns:
    list: The shuffled list (the same list passed in, shuffled in place).
    """
    random.shuffle(items)
    return items                
              
Tags: