[GIS] Using python string wild cards within the field calculator ArcGIS 10.3.1

arcgis-10.3arcgis-desktopfield-calculatorpython

I have two fields. One field has an ID. The other field has a list of ID's. Using the Field Calculator I with to calculate 1 or 0 if either field contain the same ID number. I was successful at writing an arcpy row by row query, but there's millions or records and a linear test of rows is not efficient. I need to calculate it in one hit.

I need to take a field and make it's value a wild card and test the other field for that value. I have tried the "*" and "in" methods. But it's not returning the correct value.

Can someone assist me in why this is wrong?

enter image description here

Code One:

def myCal(reportnumber,spatialjoin):
 reportnumbercheck = ('*'+(str(reportnumber))+'*')
 if (reportnumbercheck in spatialjoin):
  return 1
 else:
  return 0

Best Answer

This should just work as a normal string in check

def myCal(reportnumber, spatialjoin):
 if reportnumber in spatialjoin:
  return 1
 else:
  return 0

or even one like:

def myCal(reportnumber, spatialjoin):
   return 1 if reportnumber in spatialjoin else 0
Related Question