mercredi 21 juin 2017

Why my Choice Python 3.6 Random doesn't work properly?

i have a problem... my little function doesn't works as i expect ;)

def GenererList(nb_element):
    lst_elm=[{'ma_class':'1-3','the_next':'2-3','pk':''},{'ma_class':'2-3','the_next':'1-3','pk':''},{'ma_class':'1-2','the_next':'1-2','pk':''}]
    elm ={}
    a=0
    lst_retour = []
    while a < nb_element :
        print(a)
        elm = choice(lst_elm)
        print(elm)
        elm['pk']="%s" %a
        print(elm)
        lst_retour.append(elm)
        elm ={}
        a=a+1

    return lst_retour

I make choice in lst_elm, but at a moment, choice are made in lst_retour instead of lst_elm...

Why ??? Here you can test : https://repl.it/IwEj/0




Aucun commentaire:

Enregistrer un commentaire