Keep the variable a outside loop.
def deviser(n):
a=[];
i=1;
while( i<= n):
x=n%i;
if( x == 0 ):
p = a.insert(0, i);
print i;
i = i+1;
return a;
>>> deviser(18)
1
2
3
6
9
18
[18, 9, 6, 3, 2, 1]
>>>
solved How can i make self updating list in python?