Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If Comprehension in list

Hello,

I am knew to SageMath and Python. I hope to learn Python after I finish C++.

I would like to compare two lists and place the larger value from list L2 in another list if it is greater than L3 but not in the list if less than. Here is my try:

L2 =[sum(divisors(i))-i for i in range(1,100,1)]
print L2

L3 =[i for i in range(1,100,1)]
print L3

L4 =[L2[i] if L2[i] > L3[i] for i in range(1,100,1)]
print L4

I get the following error:

File "<ipython-input-1-01c49b9c5559>", line 20
    L4 =[L2[i] if L2[i] > L3[i] for i in range(Integer(1),Integer(100),Integer(1))]
                                  ^
SyntaxError: invalid syntax