AnsweredAssumed Answered

Find Values in Field With List Comprehension

Question asked by jpilbeam Champion on Oct 8, 2020
Latest reply on Oct 13, 2020 by rvburton

I was wondering if I was on the right track with this. I have a table with fields that contain addresses like this:

515 S WEBER RD APT 108 LOCKPORT, IL 60441

 

I'm interested in finding three types of values if they exist, and I'd like to update the value to a new field called 'UnitType'. Right now, this is printing empty brackets. I'm not too sure why.

fc = r'C:\Users\jpilbeam\Downloads\AddPts_AptUnitSte.gdb\Default.gdb\AddPts_AptUnitSte'
field = 'USPS_ADDRE'
values = ['Apt', 'Unit', 'Ste']

# Use SearchCursor with list comprehension to return a
# unique set of values in the specified field
v = [row[0] for row in arcpy.da.SearchCursor(fc, field)]
types = [i for i in v if i in values]
print(types)


>>>[]

Outcomes