|   | 1 |  initial version  | 
the syntax for list comprehension with a condition is at the end, for example:
sage: [i for i in srange(-3, 3) if i^2 == 4]
[-2, 2]
then:
sage: L2 =[sum(divisors(i))-i for i in srange(1, 100, include_endpoint=True)]
sage: L3 = srange(1, 100, include_endpoint=True)
sage: L4 = [L2[i] for i in range(100) if L2[i] > L3[i]]
sage: L4
[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]
for this use and further learning material, consider giving a try to the Programming in Python and Sage Thematic Tutorial. there are even exercises!
|   | 2 |  No.2 Revision  | 
the syntax for list comprehension with a condition is at the end, for example:
sage: [i for i in srange(-3, 3) if i^2 == 4]
[-2, 2]
then:
sage: L2 =[sum(divisors(i))-i = [sum(divisors(i))-i for i in srange(1, 100, include_endpoint=True)]
sage: L3 = srange(1, 100, include_endpoint=True)
sage: L4 = [L2[i] for i in range(100) if L2[i] > L3[i]]
sage: L4
[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]
for this use and further learning material, consider giving a try to the Programming in Python and Sage Thematic Tutorial. there are even exercises! exercises!
|   | 3 |  No.3 Revision  | 
the syntax for list comprehension with a condition is at the end, for example:
sage: [i for i in srange(-3, 3) if i^2 == 4]
[-2, 2]
then:
sage: L2 = [sum(divisors(i))-i for i in srange(1, 100, include_endpoint=True)]
sage: L3 = srange(1, 100, include_endpoint=True)
sage: L4 = [L2[i] [L2i for i i, L2i in range(100) enumerate(L2) if L2[i] > L3[i]]
sage: L4
[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]
for this use and further learning material, consider giving a try to the Programming in Python and Sage Thematic Tutorial. there are even exercises!
|   | 4 |  No.4 Revision  | 
the syntax for list comprehension with a condition is at the end, for example:
sage: [i for i in srange(-3, 3) if i^2 == 4]
[-2, 2]
then:
sage: L2 = [sum(divisors(i))-i for i in srange(1, 100, include_endpoint=True)]
sage: L3 = srange(1, 100, include_endpoint=True)
sage: L4 = [L2i for i, L2i in enumerate(L2) if L2[i] > L3[i]]
sage: L4
[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]
for this use and further learning material, consider giving a try to the Programming in Python and Sage Thematic Tutorial. there even are even exercises!
|   | 5 |  No.5 Revision  | 
the syntax for list comprehension with a condition is at to write the end, if clause after the loop iterable, for example:
sage: [i for i in srange(-3, 3) if i^2 == 4]
[-2, 2]
then:
sage: L2 = [sum(divisors(i))-i for i in srange(1, 100, include_endpoint=True)]
sage: L3 = srange(1, 100, include_endpoint=True)
sage: L4 = [L2i for i, L2i in enumerate(L2) if L2[i] > L3[i]]
sage: L4
[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]
for this use and further learning material, consider giving a try to the Programming in Python and Sage Thematic Tutorial. there even are exercises!
|   | 6 |  No.6 Revision  | 
the syntax for list comprehension with a condition is to write the if clause after after the loop iterable, for example:
sage: [i for i in srange(-3, 3) if i^2 == 4]
[-2, 2]
then:
sage: L2 = [sum(divisors(i))-i for i in srange(1, 100, include_endpoint=True)]
sage: L3 = srange(1, 100, include_endpoint=True)
sage: L4 = [L2i for i, L2i in enumerate(L2) if L2[i] > L3[i]]
sage: L4
[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]
for this use and further learning material, consider giving a try to the Programming in Python and Sage Thematic Tutorial. there even are exercises!
 Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.
 
                
                Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.