You can download this code by clicking the button below.
This code is now available for download.
Shuffles the elements of a list using the Fisher-Yates algorithm.
Technology Stack : random, list
Code Type : Function
Code Difficulty : Intermediate
import random
def shuffle_list(input_list):
"""
Shuffle a list using the Fisher-Yates algorithm.
"""
output_list = input_list.copy()
for i in range(len(output_list) - 1, 0, -1):
j = random.randint(0, i)
output_list[i], output_list[j] = output_list[j], output_list[i]
return output_list