0

I want a list of all the lists obtained by rotating an initial list.

def rotation(l):
    list_states = []
    longueur = len(l)
    cpt = 1
    liste1 = l
    while(cpt < longueur):
        last = liste1.pop()
        liste1.insert(0, last)
        print(liste1)
        list_states += [liste1]
        cpt += 1
    return list_states

I guess the issue here is that Python adds the variable liste1 which is always referenced as "l" in the memory (id(liste1) = id(l)) so list_states is made of only one list, even tough when I print liste1, I see the value is the one I want. How can I make this code work ?

user5049567
  • 99
  • 1
  • 8

0 Answers0