0

After a spatial join (one-to-one) in ArcGIS my result looks like this: (I use a / as delimiter)

2015/2015/2014/2014/2013

After that i use python in calculate field to filter out duplicate values in the field:

def removeDup(Field, delim):  
   strList = Field.split(delim)  
   strSet = set(strList)  
   str = delim  
   conStr = str.join(strSet)  
   return conStr

removeDup(!Years!, "/")

So the result looks like this:

2015/2014/2013

Now I want to sort the values ascending in the field so it would look like this:

2013/2014/2015

Any ideas on how to accomplish this?

2 Answers 2

1

Try sorting the list:

def removeDup(Field, delim):  
   strList = sorted(Field.split(delim))
   strSet = set(strList)  
   str = delim  
   conStr = str.join(strSet)  
   return conStr

removeDup(!Years!, "/")
1

Thanks for the input kttii, but I still got the same result.

But when i modify your example like this it works!

def removeDup(Field, delim):  
   strList = Field.split(delim) 
   strSet = sorted(set(strList))  
   str = delim  
   conStr = str.join(strSet)  
   return conStr

removeDup(!Years!, "/")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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