Skip to main content
added 124 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

You can use the in operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

And instead of writing 24 if statements you can use a dictionary:

d = {'1.':1, '2.':2, '3.':3} #add all values here

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        for key in d:
            if key in row[0]:
                row[1]=d[row[0]]
                cursor.updateRow(row)

But this wont work since '2.' is in both '12.' and '22.' so you can do:

row[1] = row[0].split('-')[2].split('.')[0]

You can use the in operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

And instead of writing 24 if statements you can use a dictionary:

d = {'1.':1, '2.':2, '3.':3} #add all values here

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        for key in d:
            if key in row[0]:
                row[1]=d[row[0]]
                cursor.updateRow(row)

You can use the in operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

And instead of writing 24 if statements you can use a dictionary:

d = {'1.':1, '2.':2, '3.':3} #add all values here

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        for key in d:
            if key in row[0]:
                row[1]=d[row[0]]
                cursor.updateRow(row)

But this wont work since '2.' is in both '12.' and '22.' so you can do:

row[1] = row[0].split('-')[2].split('.')[0]
added 367 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

You can use the in operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

And instead of writing 24 if statements you can use a dictionary:

d = {'1.':1, '2.':2, '3.':3} #add all values here

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        for key in d:
            if key in row[0]:
                row[1]=d[row[0]]
                cursor.updateRow(row)

You can use the in operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

You can use the in operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

And instead of writing 24 if statements you can use a dictionary:

d = {'1.':1, '2.':2, '3.':3} #add all values here

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        for key in d:
            if key in row[0]:
                row[1]=d[row[0]]
                cursor.updateRow(row)
added 107 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

You can use the inin operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

You can use in, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...

You can use the in operator, for example:

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        if '1.' in row[0]:
            row[1] = 1
...
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187
Loading