def unique_by_id_and_kind_sort(seq):
 seq.sort(key=(lambda x: x.get('sort_order', 0)))
 seen = {}
 result = []
 for item in seq:
  marker = (item.get('id') + item.get('kind'))
  if (marker in seen):
   continue
  seen[marker] = 1
  result.append(item)
 return result

def unique_by_id_and_kind_sort ( seq ) : seq . sort ( key = ( lambda x : x . get ( 'sort_order' , 0 ) ) ) seen = { } result = [ ] for item in seq : marker = ( item . get ( 'id' ) + item . get ( 'kind' ) ) if ( marker in seen ) : continue seen [ marker ] = 1 result . append ( item ) return result
due to the fact that we have duplicate content items for the same content id in our topic tree .