What if your list is not created by a formula, like
, but instead by a condition,
like ``all primes
for which
divides
and
''?
One way is to add a conditional statement to the for-loop,
for example:
> L:=[]; > for i in [1..100] do for> if IsPrime(i) and i mod 4 eq 3 then for|if> L:=Append(L,i); for|if> end if; for> end for; > L; [ 3, 7, 11, 19, 23, 31, 43, 47, 59, 67, 71, 79, 83 ]
To find a subsequence of a sequence
satisfying a property
, use the
. For example,
to find all the elements in List1 which are less than or
equal to 4, type
> List1:=[2^i:i in [1..3]]; > List1_2:=[j : j in List1 | j le 4]; > List1_2; [ 2, 4 ]