Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
31 lines (26 loc) · 774 Bytes

shuffle.md

File metadata and controls

31 lines (26 loc) · 774 Bytes
title type tags cover dateModified
Shuffle list
snippet
list
random
tent-stars
2020-11-02 19:28:35 +0200

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]