Randomly Shuffle a List

  • Share this:

Code introduction


This function takes a list as an argument and returns a new list with the elements shuffled randomly.


Technology Stack : random

Code Type : Function

Code Difficulty :


                
                    
import random

def shuffle_list(input_list):
    """
    将输入列表中的元素随机打乱。

    :param input_list: 要打乱的列表。
    :return: 随机打乱后的列表。
    """
    shuffled_list = input_list[:]
    random.shuffle(shuffled_list)
    return shuffled_list

# JSON representation of the code                
              
Tags: