Skip to content

Instantly share code, notes, and snippets.

@cindygis
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/115c37b0f1b2624de551 to your computer and use it in GitHub Desktop.
Save cindygis/115c37b0f1b2624de551 to your computer and use it in GitHub Desktop.
Displays the key values that are duplicates in a list of attribute field values.
#
# @date 29/05/2015
# @author Cindy Williams
#
# Checks an attribute field for duplicate values,
# and displays them along with the amount of duplicates.
#
# For use in the Python window in ArcMap.
#
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
lyrs = arcpy.mapping.ListLayers(mxd)
def checkDuplicate(ftr, field):
vals = [row[0] for row in arcpy.da.SearchCursor(ftr, field)]
dct = {x:vals.count(x) for x in vals}
print ftr.name
for k, v in dct.iteritems():
if v > 1:
print k, v
for lyr in lyrs:
field_name = arcpy.ListFields(lyr, "*_ID")[0].name
checkDuplicate(lyr, field_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment