def test_unique(): tests = [('aabbcc', 'abc'), ('aa', 'a'), (([1, 2], [1, 2], [3, 4], 5, 5, 5), ([1, 2], [3, 4], 5))] for test, result in tests: Assert(list(unique(test))) == list(result) Assert(list(unique('aaabbbbccc', seen='ab'))) == ['c']
def test_unique(): tests = [ ('aabbcc', 'abc'), ('aa', 'a'), (([1, 2], [1, 2], [3, 4], 5, 5, 5), ([1, 2], [3, 4], 5)) ] for test, result in tests: Assert(list(unique(test))) == list(result) Assert(list(unique('aaabbbbccc', seen='ab'))) == ['c']
def __init__(self, *args, **kwargs): if len(args) > 1: raise TypeError( 'expected at most 1 argument, got %d' % len(args) ) arg = [] if args: mapping = args[0] if isinstance(mapping, self.__class__): arg = ((k, l[:]) for k, l in mapping.iterlists()) elif hasattr(mapping, 'iteritems'): for key, value in mapping.iteritems(): if isinstance(value, (tuple, list)): value = list(value) else: value = [value] arg.append((key, value)) else: keys = [] tmp = {} for key, value in mapping or (): tmp.setdefault(key, []).append(value) keys.append(key) arg = ((key, tmp[key]) for key in unique(keys)) kws = {} for key, value in kwargs.iteritems(): if isinstance(value, (tuple, list)): value = list(value) else: value = [value] kws[key] = value super(MultiDictMixin, self).__init__(arg, **kws)
def remaining_params(self): return unique(self.params, set(self.args) - self.changeable_args)
def __iter__(self): return unique(chain.from_iterable(d.iterkeys() for d in self.dicts))