I have a list of addresses that I need to contact. Some are listed in the attribute table, and some aren't. I'm trying to find the ones that aren't.

The list:

contacted = ['123 STOWE ST', '123 ROSE DR', '124 ROSE DR', '125 ROSE DR', etc.]

The attribute table has a Property_Street field that lists addresses. I want to figure out which addresses are in the contacted list and are not in the Property_Street field.

The only thing I've figured out so far is to isolate the records that have been confirmed as contacted based on the 'Contacted' field in the attribute table. But it returns a layer, not a field, and I don't know how to isolate the Property_Street field from that layer.

query = "\"CONTACTED\" = 1"
contacted_in_tbl = arcpy.SelectLayerByAttribute_management("hot_zone", "NEW_SELECTION", query)
  • 3
    To get a list off all addresses to subtract your list of contacted addresses from I would use list comprehension with s search cursor.
    – PolyGeo
    Jun 7 '19 at 21:50
  • 1
    Join tables. Records with no match is your answer.
    – FelixIP
    Jun 8 '19 at 0:40
  • You can also use a WHERE field NOT IN (SELECT field FROM table) subselect construct (if the data source supports it)
    – Vince
    Jun 8 '19 at 1:49

If you want to use python then use sets:

A set object is an unordered collection of distinct hashable objects. Common uses include membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference

contacted = ['123 STOWE ST', '123 ROSE DR', '124 ROSE DR', '125 ROSE DR']
attr = ['123 STOWE ST', '123 ROSE DR', '124 ROSE DR']

#Same as

['125 ROSE DR']
['125 ROSE DR']

List all adresses using da.SearchCursor and list comprehension:

import arcpy
in_attribute_table = [i[0] for i in arcpy.da.SearchCursor(fc,'PROPERTY_STREET')]
diff = list(set(contacted)-set(in_attribute_table))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.