In my script I need to generate a simple list of [1,2,3,4] values and then shuffle each one of those lists inside this list individually. I used random.shuffle() function which works fine on single arrays, but when I try to use it in a for loop the output is a list of shuffled arrays, but all of them identical:
[3, 1, 2, 4]
[3, 1, 2, 4]
[3, 1, 2, 4]
etc...
I have tried running the script with different python versions (2.7, 3.6) but the problem persists.
Here is a simplified code that represents the issue:
import random
numbers_list = [1,2,3,4]
#make a list of 10 numbers_list
list_of_lists = [numbers_list]*10
#shuffle every list inside list_of_lists
for i in list_of_lists:
random.shuffle(i)
#print every list from list_of_lists
for a in list_of_lists:
print(a)
Running the script multiple times results in different lists, but they always consist of a repeated one array. What can I do to fix it? Is it an issue with random.shuffle() or my script? What am I doing wrong?