You can download this code by clicking the button below.
This code is now available for download.
This function takes a list as input and then shuffles the elements of the list in place using the Fisher-Yates shuffle algorithm.
Technology Stack : Built-in function random.randint(), list comprehension, tuple unpacking
Code Type : Function
Code Difficulty : Intermediate
import random
def shuffle_list(input_list):
if not isinstance(input_list, list):
raise ValueError("Input must be a list")
for i in range(len(input_list) - 1, 0, -1):
j = random.randint(0, i)
input_list[i], input_list[j] = input_list[j], input_list[i]
return input_list