Making a function work for higher cases of iteration    
   For constructing the Generalized Sierpinski graph as described in this paper, I wrote the following code:
def Sier(g,k,m):
for i in range(1,k):
    h = Graph()
    for j in range(0, m):
        perm = {u: (j, u) for u in g}
        gg = g.relabel(perm=perm, inplace=False)
        h.add_edges(gg.edges())
        n1 = [((a, b), (b, a)) for (a, b) in h]
        n2 =[((a,a),(a,a)) for (a,b) in h]
        x=set(n1)-set(n2)
        h.add_edges(list(x))
    g=h
return h
The parameters of the function Sier are g :graph, k :the k-th iterate of Sierpinski construction, m :the order of the graph g. The code works fine only for k=2. When I put k=3, I do not get the expected output of the graph. How do I modify the code to get the desired output for any value of k? Thanks beforehand.
 
 
What do you mean under "I do not get the expected output"? Please elaborate. Also, how exactly do you call your function - what
gandmdo you specify?