In-Place List Shuffling with Python#s random.shuffle

  • Share this:

Code introduction


This function takes a list as an argument and then uses the shuffle function from the random module to shuffle the items in the list in-place, and finally returns the shuffled list.


Technology Stack : random module

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def shuffle_list(items):
    """
    Shuffle the items in the list in-place.
    """
    random.shuffle(items)

    return items                
              
Tags: