Files
30-seconds-of-code/snippets/shuffle.md
Angelos Chalaris fad8bd3e8a Update covers
2023-02-16 22:24:35 +02:00

794 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Shuffle list list,random tent-stars 2018-01-19T11:59:33+02:00 2020-11-02T19:28:35+02:00

Randomizes the order of the values of an list, returning a new list.

from copy import deepcopy
from random import randint

def shuffle(lst):
  temp_lst = deepcopy(lst)
  m = len(temp_lst)
  while (m):
    m -= 1
    i = randint(0, m)
    temp_lst[m], temp_lst[i] = temp_lst[i], temp_lst[m]
  return temp_lst
foo = [1, 2, 3]
shuffle(foo) # [2, 3, 1], foo = [1, 2, 3]