On 2012-1-02 09:24, Eric Kangas wrote:
l1 = [int(x) for x in p]
l2 = [int(x) for x in d]
l3 = []
x = 0
for x in l1,l2:
This will give x the values l1 and l2,
which are not valid indices.
> if l1[x:x+1]==l2[x:x+1];
> l3.insert(x, (x,l1[x:x+1],l2[x:x+1]));
Why ranges (which are lists) rather than simple items?
Why record two numbers that are always equal (or else unrecorded)?
Is "l3.insert(x, ...)" valid when len(l3) < x?
Others have suggested how to do it with a one-liner.
Here's better syntax for the 'naive' approach:
for x in range(min(len(l1),len(l2)):
if l1[x] == l2[x]:
l3.append((x,l1[x]))
print l3
--
Anton Sherwood *\\* www.bendwavy.org *\\* www.zazzle.com/tamfang
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org