# Using python string wild cards within the field calculator ArcGIS 10.3.1

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?

Code One:

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

• Why doesn't reportnumber in spatialjoin work? There is no wildcard in check like that in Python. – Nathan W Jul 13 '15 at 3:48
• Ah ha. I had included the wild card in the "in" method... – GISI Jul 13 '15 at 4:08

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


i haven't tested it, but you may not need the wildcards at all - if you convert the value in the spatial join field to a list - something like

def myCal(reportnumber,spatialjoin):
#spatialjoin = spatialjoin.split(';')
if reportnumber in spatialjoin:
return(1)
else:
return(0)


heck, may not even need to convert spatial join to a list... indeed, no list conversion needed - i'll comment out that part...