You can download this code by clicking the button below.
This code is now available for download.
This function takes a list as an argument and then uses the shuffle method from the random library to randomly shuffle the order of the elements in the list. It returns the shuffled list.
Technology Stack : random, list
Code Type : Function
Code Difficulty : Intermediate
import os
import sys
import random
import json
import datetime
import re
import time
import math
def shuffle_list(input_list):
"""Randomly shuffle the elements of the input list.
Args:
input_list (list): The list to be shuffled.
Returns:
list: A shuffled version of the input list.
"""
shuffled_list = input_list[:]
random.shuffle(shuffled_list)
return shuffled_list
# Example usage:
# my_list = [1, 2, 3, 4, 5]
# shuffled = shuffle_list(my_list)
# print(shuffled)