I have a list:
li = [0, 0, 2313, 1221, 0, 1333, 66, 0, 0, 0, 0]
and another list of lists, where:
The list of lists is called disciplines (below). The lists that are within disciplines, are specified below also:
#essas são as listas que estão dentro de disciplinas:
cs = [2313, 2214, 2120]
gav = [1101, 1103, 1104]
icc = [3201, 3304, 3209]
comp = [4101, 4203, 4409, 4559]
#lista de listas
disciplinas = [cs, gav, icc, comp]
I need to sort by a draw from the disciplines list a value ( cs
or gav
or icc
or comp
). I thought about using the choice()
method. After the value is chosen randomly, I must remove it from disciplines and add in li
in a random position of li
, only where zero. I have to do this while disciplines are different from zero.
OBS: I should add the value of disciplines only one followed by another, never isolated, so that it looks like this:
li = [cs, cs, 2313, 1221, 0, 1333, 66, icc, icc, gav, gav]
I've already been able to find a way to distribute in positions where I find zero (in the example below, I substituted 0 for 1), so that I can only place the item if the current_table and current_table + 1 OR current_table and current_table_1 are equal to zero:
l = [0, 0, 2313, 1221, 0, 1333, 66, 0, 0, 0, 0]
lCount = len(l)
next1 = False
for i in range(0, lCount-1):
if(l[i] == 0 and l[i+1] == 0):
l[i] = 1
l[i+1] = 1
next1 = True
if(next1): # ultimo elemento caso seja 0 seguido de outro (next1 definido no ultimo loop do ciclo)
l[-1] = 1
print(l) # [1, 1, 2313, 1221, 0, 1333, 66, 1, 1, 1, 1]
Thank you!