jahood

ArcPy / Python:  Join two lists (and more , big problem!)

Discussion created by jahood on Apr 13, 2011
Latest reply on Apr 14, 2011 by jahood
Hello,

First my of my experience with python is in 9.3x and I only just started on arc10 and arcpy last week! This means I am Newb all over again.


I have a large dataset that contains latitude and longitude fields. These fields are stored as such:

111-22-22, 23-4-55, 33-3-3 etc,

For labeling purposes we would like to convert and store these in their standard display format as such: 103°22'77"


I have encountered a number of issues and am now doubting if this is possible. I would like to solve how to join two lists, however.


Essentially I have done the following:

Update_cursor = arcpy.UpdateCursor(feature_class)
For rows in update cursor:
    coord = rows.latitude
    courd_list = coord.split("-")  #This should print something like ["000", "00", "00"]
    Symbol_list = ["°", "'", "''"]




So what I would like to do is join the coord_list with the symbol_list but not just join, splice....

In theory it would give me the result I need.

I went about it many different ways and when each one failed, I seem to have erased them and moved on to the next which is a shame because I would have liked to have shared with you my process.

One method that I think might be the answer is the following which I gleaned from the old forums but I can't remember who suggested it and I have deleted the link already :




symbol = ["°", "'", "''"]

values = ["100-22-111", "12-232-22", "33-3-33", "993-34-7"]

testSet1 = set()
for v in values:
   testSet1.add(v)
testSet2 = set()
for s in symbol:
   testSet2.add(s)
print set.union(testSet1, testSet2)

PRINTS  set(["''", '12-232-22', "'", '\xb0', '100-22-111', '33-3-33', '993-34-7'])


My Problems:

This would seem to work EXCEPT even though I asked python to union set1 then set2, it seems to union in reverse.
Specifically, the symbols set, set2, is unioned in reverse, putting the ° at the end and the '' at the beginning...
I could fix both of these I guess by formatting my code but what if it is not consistant?


The character ° does not seem to be supported by python, can anybody confirm this? In my test result , the ° is converted to \xb0. Is there an ascii or some other module to import so that python will support it?

Finally, if I am able to ge the lists to properly union, I will need to output them to a single starting from position 1 in the list and moving to the last , before I can re assign this to the new field in the table.

For some reason I can't figure out how to output multiple instances in a List to create 1 back to back string.




I appriciate any ideas or comments!
Thanks

James

Outcomes