def extend(self, objects): """ Extends the list with the given `objects`. """ if self.exhausted: self._collected_data.extend(objects) else: self._iterator = chain(self._iterator, objects)
def elements(self): """ Iterator over the elements in the counter, repeating as many times as counted. >>> from brownie.datastructures import Counter >>> sorted(Counter('abcabc').elements()) ['a', 'a', 'b', 'b', 'c', 'c'] """ return chain(*starmap(repeat, self.iteritems()))
def __add__(self, other): if isinstance(other, (list, self.__class__)): return self.__class__(chain(self, other)) raise TypeError("can't concatenate with non-list: {0}".format(other))
def symmetric_difference(self, other): other = self.__class__(other) return self.__class__(chain(self - other, other - self))
def test_chain(): list(chain([1, 2], [3, 4])) == [1, 2, 3, 4] list(chain.from_iterable([[1, 2], [3, 4]])) == [1, 2, 3, 4]
def test_chain(): Assert(list(chain([1, 2], [3, 4]))) == [1, 2, 3, 4] Assert(list(chain.from_iterable([[1, 2], [3, 4]]))) == [1, 2, 3, 4]