I have an initial list, comprising 1000 lists, some empty and some not. I'm trying to disperse 2000 floats amongst those empty lists at random(empty_list45, empty_list2, ..., empty_randn), not in order (empty_list1, empty_list1, ..., empty_listn).
Here's my attempt:
#the list containing lists.
folder = [[]] * 1000
for i in range(len(newOPsys_i)):
folder[newOPsys_i[i]] = (newOP[i])
#list of indices of empty lists in folder, where folder is the list comprising 1000 lists that may or may not be empty
empty = []
for i in range(len(folder)):
if not folder[i]:
empty.append(i)
#function that pulls a random index from any called list
def rand(mylist):
rando = random.randint(0,len(mylist)-1)
return(rando)
#my attempt at appending 2000 floats to random empty lists in folder
for i in range(0,2000):
x = empty[rand(empty)]
print(folder[x])
folder[x].append(match[x][random.randint(0,len(match[x])-1)]) #match is a separate list where I wish to pull the floats from, and place them into the empty lists.
My output looks something like:
[]
[3.9]
[3.9, 7.8]
[3.9, 7.8, 54.9]
From the print, what seems to be happening instead is that in the first iteration an empty list is found then a single float is appended. On the next iteration, another empty list is randomly found, but appended to this empty list is the float from the last iteration, along with a new float. This is not what I want to happen, I just want those single random floats appended each iteration. Any insights? Thanks in advance.