On 3/30/12 11:41 AM, Eric Kangas wrote:
Hi,
I am trying to find the values, and locations of those values in a
sequence of numbers. I have written up code that I thought would work,
but it doesn't. Here is the code:
l31 = [len(l3[i]) for i in range(a/len(l))];
l32 = [];
l33 = [if x=6: l32.append((x,l31[x])) for x in l31];
I get the normal invalid syntax error. What am I missing in this code
for the line with l33 = ?
I think enumerate is your friend:
http://docs.python.org/library/functions.html#enumerate
sage: a=[1,2,3,1,4,3,3,3,4,6,5,4,3,2,4]
sage: [(i,val) for i,val in enumerate(a) if val==4]
[(4, 4), (8, 4), (11, 4), (14, 4)]
Thanks,
Jason
--
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