duplicate items in a list
Fredrik Lundh
fredrik at pythonware.com
Mon Nov 21 06:18:33 EST 2005
Shi Mu wrote:
> I used the following method to remove duplicate items in a list and
> got confused by the error.
>
> >>> a
> [[1, 2], [1, 2], [2, 3]]
> >>> noDups=[ u for u in a if u not in locals()['_[1]'] ]
that's not portable, relies on CPython 2.4 implementation details, and
shouldn't be used unless you understand exactly why it shouldn't be
used. please pick another solution from the cookbook page.
(fwiw, this shows why the activestate cookbook needs an editor, and
why "user-annotated documention" means that the documentation will
be no better than the dumbest contributor)
</F>
More information about the Python-list
mailing list