Tekkaman wrote: > I have a list of lists and I want to define an iterator (let's call > that uniter) over all unique elements, in any order. For example, > calling: > > sorted(uniter([['a', 'b', 'd'], ['b', 'c'], ['a', 'c', 'd']])) > > must return ['a', 'b', 'c', 'd']. I tried the following > implementations: > > from itertools import chain > def uniter1(listOfLists): > for item in set(chain(*listOfLists)): yield item
def uniter(lists): return iter(set(chain(*lists))) This avoids the explicit for-loop. Peter -- http://mail.python.org/mailman/listinfo/python-list