Theo_E

SearchCursor and loop problem

Discussion created by Theo_E on Jul 4, 2011
Latest reply on Jul 6, 2011 by Theo_E
Dear all,
I have a table with a field named « ADRESSE_ID » (long integer). Let???s say it has 10 rows with values going from 1 to 10 (values stored in the « temptab » table in my script). My goal is to create all the possible couple of values, in example:
1 - 1
1 - 2
1 - 3
1 - 4
1 - 5
1 - 6
1 - 7
1 - 8
1 - 9
1 - 10
2 - 1
2 - 2
Etc???

Each couple of value will be a string, and should be stored in the table named  "tablefinal??? ("OD_NAME??? field).  Obviously I???m doing something wrong with the loop as I got only (the value "3 ??? 3???, "4 ??? 4???, "5 -5???, "6 ??? 6???, "7 ??? 7???, "8 ??? 8???, "9 ??? 9??? and "10 ??? 10???. Any help or idea are welcome :)

Here's my script
#Create new table and add the field OD_NAME
arcpy.CreateTable_management(env.workspace, "tablefinal")
arcpy.AddField_management("tablefinal","OD_NAME","TEXT","40")
tablefinal="tablefinal"

#Cursor to add value in the tablefinal
tablefinal=arcpy.InsertCursor(tablefinal)

#Searching for the ADRESSE_ID values in the temptab table. Looping to create the values of OD_NAME
origin = arcpy.SearchCursor(temptab, "", "", "ADRESSE_ID", "ADRESSE_ID A")
for i in origin:
    for j in origin:
        for k in origin:
            t_row=tablefinal.newRow()
            t_row.OD_NAME=str(i.getValue("ADRESSE_ID")) + " - " + str(j.getValue("ADRESSE_ID"))
            tablefinal.insertRow(t_row)


By the way, I've been able to do it with python list, but outside of arcgis programming.
list1 = [1,2,3,4]
list2 = list1
result = []
for i in list1:
    for j in list2:
        result.append('-'.join((str(i), str(j))))



Thanks in advance for your help,
Best regards,
Theo

Outcomes