def sanitize_choices(choices, choices_all):
 seen = set()
 others = [x for x in choices_all if (x not in choices)]
 res = []
 for s in choices:
  if (s in (list(choices_all) + ['*'])):
   if (not ((s in seen) or seen.add(s))):
    res.extend((list(others) if (s == '*') else [s]))
 return res

def sanitize_choices ( choices , choices_all ) : seen = set ( ) others = [ x for x in choices_all if ( x not in choices ) ] res = [ ] for s in choices : if ( s in ( list ( choices_all ) + [ '*' ] ) ) : if ( not ( ( s in seen ) or seen . add ( s ) ) ) : res . extend ( ( list ( others ) if ( s == '*' ) else [ s ] ) ) return res
clean up a stringlist configuration attribute: keep only choices elements present in choices_all .