Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Creating list within an outer for loop counter


I want to create one list for L. I gave an example from the list tutorial(list1) that does what I want to do. I believe I have to include the for loop inside the brackets [] but cannot figure it out. I do not know how to program in Python. I am learning C++ now and hope to learn Python next.

for i in range (1,100,1):
    div = divisors(i)
    length = len(div)
    L = [sum(div[k] for k in range(length))-i]
    print i, 

    print L

list1 =[j for j in range(6)] 
print list1