Skip to main content
2 de 7
conteúdo editado
Miguel
  • 29,5mil
  • 5
  • 43
  • 80

Exatamente com choice dá para fazer, deve importar o modulo random:

import random

cs = [2313, 2214, 2120]
gav = [1101, 1103, 1104]
icc = [3201, 3304, 3209]
comp = [4101, 4203, 4409, 4559]

disciplinas = [cs, gav, icc, comp]
l = [0, 0, 2313, 1221, 0, 1333, 66, 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] = random.choice(disciplinas)
        next1 = True
    elif(next1):
        l[i] = random.choice(disciplinas)
        next1 = False
        
if(next1): # ultimo elemento caso seja 0 seguido de outro (next1 definido no ultimo loop do ciclo)
    l[-1] = random.choice(disciplinas)
print(l) # [[2313, 2214, 2120], [2313, 2214, 2120], 2313, 1221, 0, 1333, 66, [3201, 3304, 3209], [2313, 2214, 2120], [3201, 3304, 3209]]
Miguel
  • 29,5mil
  • 5
  • 43
  • 80