Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

While loop with recording intermediate steps

Sory for a certainly too long code but the problem is in while the loop

def All_pref(cand=["A","B","C","D"],code=1) :
    ncand=len(cand)
    Scand=sorted(Set(cand))
    all_pref=Arrangements(Scand,ncand).list()
    all_pref1=[str(Word(x)) for x in all_pref]
    if code==1 :
        return ncand
    if code==2 :
        return all_pref1

cand=["A","B","C","D"]    
Ap=All_pref(cand,2)
ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5]
alf=[list(build_alphabet(x)) for x in Ap]
show(alf)
resultats={}
alfc={}
iteration=0
while len(alf[0])>0:
    show(alf)
    resultats[iteration]={}
    premier_par_pref =[[ne[i] if alf[i].index(x)==0 else 0 for i in range(len(alf))] for x in cand]
    nb_fois_premier_par_pref = [add(x) for x in premier_par_pref]
    show(nb_fois_premier_par_pref)
    min_nb_fois_premier_par_pref = min(nb_fois_premier_par_pref)
    index_min_nb_fois_premier_par_pref = nb_fois_premier_par_pref.index(min_nb_fois_premier_par_pref)
    cand_el=cand[index_min_nb_fois_premier_par_pref]
    show(cand_el)
    resultats[iteration]["elimine"]=cand_el
    alfc[iteration]=alf.copy()
    show(alfc[iteration])        
    resultats[iteration]["liste"]=alfc[iteration]
    [x.remove(cand_el) for x in alf]
    cand.remove(cand_el)
    iteration+=1
show(resultats)

if you look at the final result it is empty. Where do I fail ?

While loop with recording intermediate steps

Sory Sorry for a certainly too long code but the problem is in the while the loop

def All_pref(cand=["A","B","C","D"],code=1) :
    ncand=len(cand)
    Scand=sorted(Set(cand))
    all_pref=Arrangements(Scand,ncand).list()
    all_pref1=[str(Word(x)) for x in all_pref]
    if code==1 :
        return ncand
    if code==2 :
        return all_pref1

cand=["A","B","C","D"]    
Ap=All_pref(cand,2)
ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5]
alf=[list(build_alphabet(x)) for x in Ap]
show(alf)
resultats={}
alfc={}
iteration=0
while len(alf[0])>0:
    show(alf)
    resultats[iteration]={}
    premier_par_pref =[[ne[i] if alf[i].index(x)==0 else 0 for i in range(len(alf))] for x in cand]
    nb_fois_premier_par_pref = [add(x) for x in premier_par_pref]
    show(nb_fois_premier_par_pref)
    min_nb_fois_premier_par_pref = min(nb_fois_premier_par_pref)
    index_min_nb_fois_premier_par_pref = nb_fois_premier_par_pref.index(min_nb_fois_premier_par_pref)
    cand_el=cand[index_min_nb_fois_premier_par_pref]
    show(cand_el)
    resultats[iteration]["elimine"]=cand_el
    alfc[iteration]=alf.copy()
    show(alfc[iteration])        
    resultats[iteration]["liste"]=alfc[iteration]
    [x.remove(cand_el) for x in alf]
    cand.remove(cand_el)
    iteration+=1
show(resultats)

if you look at the final result it is empty. Where do I fail ?