Last active
August 29, 2015 14:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# @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