Lists, Arrays, and Tuples!

I have a complicated script and a complicated problem. I have simplified it down to the following example:

I grab a field from a shapefile using updatecursor and input the field values into a list:

I need to split these lists up into integers so i can do some math on the first column of each string. (need to add 180 if < 180, and need to subtract 180 if > 180.)

Result:

So I am able to isolate the values I need to perform the math on, but how do I call them to a variable and then insert them back in?

Here is a copy of my full code for this problem, with the third segment being my failed attempt at 2 d arrays.

Error Message:

I found an exceptional resource here but it doesn't help with this problem: http://www.astro.ufl.edu/~warner/prog/python.html

Any advice?

I have a complicated script and a complicated problem. I have simplified it down to the following example:

I grab a field from a shapefile using updatecursor and input the field values into a list:

list = ["111-11-1","222-22-2","333-33-3"]

I need to split these lists up into integers so i can do some math on the first column of each string. (need to add 180 if < 180, and need to subtract 180 if > 180.)

for l in list: splitlist.append(l.split("-")) print splitlist for segment in splitlist: print segment

Result:

[['111', '11', '1'], ['222', '22', '2'], ['333', '33', '3']] ['111', '11', '1'] ['222', '22', '2'] ['333', '33', '3']

So I am able to isolate the values I need to perform the math on, but how do I call them to a variable and then insert them back in?

Here is a copy of my full code for this problem, with the third segment being my failed attempt at 2 d arrays.

list = ["111-11-1","222-22-2","333-33-3"] splitlist=[] for l in list: splitlist.append(l.split("-")) print splitlist records=0 for split in splitlist: records=records+1 print split columns=3 for j in range(records): for i in range(columns): current = splitlist[[records],[columns]] splitarray[[records],[columns]].append(current) print current print splitarray[[records],[columns]]

Error Message:

line 25, in <module> current = splitlist[[records],[columns]] TypeError: list indices must be integers, not tuple

I found an exceptional resource here but it doesn't help with this problem: http://www.astro.ufl.edu/~warner/prog/python.html

Any advice?

... which will produce...

111

222

333

So you can put each value of into a variable, load into a numeric array, test for < or >, etc.

Or am I commenting on the part that isn't the problem?

Mike, its been a while but a pleasure to see you on the internets!

I should first clarify where my problem was.

I wanted to pull values from the first position in the first list then the first position in the second list, then the 1st in the 3rd... etc.

The only caveat is that after pulling the value I wanted to be able to insert it back into the the same format but with the altered value as required.

I was getting tripped up trying to accomplish this using 2D arrays but the data I have is not actually a 2d array. Calling item[2][0] for instance should have provided me with "222" if this was a 2d array and this is where the error was happening I think.

Its simply a list of lists...

So

These have been converted from a list of 3 strings to a list of 3 lists.

Next step is to call first position from each of the lists and do the math.

I can leave my data in this format because the script I am working on uses it in this format so...

Success!