On Mar 20, 5:07 pm, Michael Spencer <m...@telcopartners.com> wrote: > Alexzive wrote: snip > And, if you really want, you can get the body of this into 1-line, noting that > seen.add returns None, so the expression (item in seen or seen.add(item)) > evaluates to True if item is in seen, or None (and item is added to seen) if > not. > > >>> seen = set() > >>> B= [item for item in A if not (item in seen or seen.add(item))] > >>> B > [1, 2, 3, 4]
IYO in your opinion, is '... or seen.add(item) is None' more or less readable? You might even want '... or ( lambda x: False )( seen.add( item ) )'. Or: '... or seen.add(item) and False'. This preserves order. -- http://mail.python.org/mailman/listinfo/python-list