code: def __select_autocomplete_identities(self, sources):
          
  
          MIN_PRIORITY = 99999999
  
          checked = {}
  
          for source in sources:
              uids = api.unique_identities(self.db, source=source)
  
              for uid in uids:
                  if uid.uuid in checked:
                      continue
  
                  max_priority = MIN_PRIORITY
                  selected = []
  
                  for identity in sorted(uid.identities, key=lambda x: x.id):
                      try:
                          priority = sources.index(identity.source)
  
                          if priority < max_priority:
                              selected = [identity]
                              max_priority = priority
                          elif priority == max_priority:
                              selected.append(identity)
                      except ValueError:
                          continue
  
                  checked[uid.uuid] = selected
  
          identities = collections.OrderedDict(sorted(checked.items(),
                                               key=lambda t: t[0]))
  
          return identities
docs: Select the identities used for autocompleting