How can you sort a set of unique values? Arcpy addin

624
2
Jump to solution
03-13-2014 02:23 PM
jasongraham
New Contributor III
I have tried many ways to sort that work, but then I can't get unique values.  The following works to return unique values, it would seem I need to add something to the onFocus part to make it work.  any suggestions?
Rng = [] for row in arcpy.SearchCursor("X:\JasonGraham\Landstatus\Data\ls2014.gdb\BaseData\Townships"):     Rng.append(row.RNG_NUMC)      class ComboBoxClass7(object): #Collect Range from list of unique values gathered from the layer     """Implementation for MTR_addin.combobox_3 (ComboBox)"""     def __init__(self):         self.value = "000"         self.items = (Rng)         self.editable = True         self.enabled = True         self.dropdownWidth = 'WWWW'         self.width = 'WWWW'     def onSelChange(self, selection):         self.sel = selection        def onEditChange(self, text):         pass     def onFocus(self, focused):#show only unique values         if focused:             values = (Rng)             uniqueValues = set(values)             self.items = []             for uniqueValue in uniqueValues:                 self.items.append(uniqueValue)       
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jasongraham
New Contributor III
I found it, so simple

[HTML] uniqueValues = sorted(set(values))[/HTML]

View solution in original post

0 Kudos
2 Replies
Zeke
by
Regular Contributor III
You can use a set to get unique values. I forget if you can sort a set, but if not you can put it in a list and sort that.
0 Kudos
jasongraham
New Contributor III
I found it, so simple

[HTML] uniqueValues = sorted(set(values))[/HTML]
0 Kudos