Random List Shuffling Function

  • Share this:

Code introduction


This function takes a list as input and then uses the shuffle function from the random module to randomly shuffle the elements of the 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.
    """
    shuffled_list = input_list[:]
    random.shuffle(shuffled_list)
    return shuffled_list                
              
Tags: