I have this simple code:
class bfs:
    vis=[]
    bags=[]
    def __init__ (self,x): 
        for i in p:    #initializes vis with len(p) zeroes 
            self.vis.append(0)
            print self.vis
        self.vis[x]=1   #marks index x as visited
        print self.vis
p=raw_input("Input values: ").split()
for i in range(0,len(p)):
    p[i]=int(p[i])
q=[]
for i in range(0,len(p)):
    q.append(bfs(i))
print
for i in q:
    print i.vis
If i input, say, any 3 numbers, why do I get this output:
[0]
[0, 0]
[0, 0, 0]
[1, 0, 0]
[1, 0, 0, 0]
[1, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 0]
[1, 1, 0, 0, 0, 0]
[1, 1, 0, 0, 0, 0, 0]
[1, 1, 0, 0, 0, 0, 0, 0]
[1, 1, 0, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 0, 0, 0, 0, 0, 0]
Instead of something like this?
[0]
[0, 0]
[0, 0, 0]
[1, 0, 0]
[0]
[0, 0]
[0, 0, 0]
[0, 1, 0]
[0]
[0, 0]
[0, 0, 0]
[0, 0, 1]
[1, 0, 0]
[0, 1, 0]
[0, 0, 1]
The program seems to just keep on working with one array in all created objs. Why is this the case?
 
     
     
    