Randomly Shuffle a List

  • Share this:

Code introduction


This function takes a list as input, then shuffles the elements of the list randomly and returns the new list.


Technology Stack : random

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def shuffle_list(input_list):
    """
    Randomly shuffles the elements of the input list.

    :param input_list: List to be shuffled.
    :return: A new list with the elements of the input_list in a random order.
    """
    shuffled_list = input_list[:]
    random.shuffle(shuffled_list)
    return shuffled_list

# JSON representation                
              
Tags: