# Revision history [back]

The question is an explicit one about how to compare two lists and make a third one out of them.

However, when programming some general considerents have priority. For instance, keep things simple. In this example case, the operation of associating the list L3 is really not indicated, what shall we do with its elements? (And even if... why not directly L3 = range(1,100)? And why redefine the one letter variable i which traditionally stays for $\sqrt{-1}$. This was the first point. Then there is an internal function computing the sum of divisors. Why not use it? Shall we consider that we have to first compute all divisors, than add them is the quick way to do the job?

Why do we need L2 ? Just to see we can associate this list as an example?!

An alternative way to get L4 without using list comprehension would be for example in sage:

L4 = []
for k in [1..100]:
s = sigma(k) - k
if s > k:
L4.append( s )

print L4

This gives:

[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]

(And of course, now we do not know which sum comes from which $k$...)

Note: This post may not answer the question directly, but it is one in a series of posts, where we simply ignore there is already a function sigma doing half of the job.

The question is an explicit one about how to compare two lists and make a third one out of them.

However, when programming some general considerents have priority. For instance, keep things simple. In this example case, the operation of associating the list L3 is really not indicated, what shall we do with its elements? (And even if... why not directly L3 = range(1,100)? And why redefine the one letter variable i which traditionally stays for $\sqrt{-1}$. This was the first point. Then there is an internal function computing the sum of divisors. Why not use it? Shall we consider that we have to first compute all divisors, than add them is the quick way to do the job?

Why do we need L2 ? (As a list, why do we not work elementwise.) Just to see we can associate this list as an example?!

An alternative way to get L4 without using list comprehension would be for example in sage:

L4 = []
for k in [1..100]:
s = sigma(k) - k
if s > k:
# print "%s = %s -> %s" % ( k, k.factor(), s )
L4.append( s )

print L4

print L4

This gives:

[16, 21, 22, 36, 42, 55, 50, 54, 76, 66, 64, 108, 78, 74, 123, 90, 106, 140, 92, 144, 156, 117]

(And of course, now we do not know which sum comes from which $k$...)$k$... We could use in the above some intermediate prints to catch this information. Then why associate a list of $100$ elements, when finally their number is smaller?)

Note: This post may not answer the question directly, but it is one in a series of posts, where we simply ignore there is already a function sigma doing half of the job.

job.