2001-09-07 18:40:38 -04:00
|
|
|
PEP: 270
|
|
|
|
Title: uniq method for list objects
|
|
|
|
Version: $Revision$
|
|
|
|
Last-Modified: $Date$
|
|
|
|
Author: jp@demonseed.net (Jason Petrone)
|
2002-11-06 00:41:32 -05:00
|
|
|
Status: Rejected
|
2001-09-07 18:40:38 -04:00
|
|
|
Type: Standards Track
|
2017-01-07 13:33:00 -05:00
|
|
|
Content-Type: text/x-rst
|
2001-09-07 18:40:38 -04:00
|
|
|
Created: 21-Aug-2001
|
|
|
|
Python-Version: 2.2
|
|
|
|
Post-History:
|
|
|
|
|
|
|
|
|
2002-11-06 00:41:32 -05:00
|
|
|
Notice
|
2017-01-07 13:33:00 -05:00
|
|
|
======
|
2002-11-06 00:41:32 -05:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
This PEP is withdrawn by the author. He writes::
|
2002-11-06 00:41:32 -05:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
Removing duplicate elements from a list is a common task, but
|
|
|
|
there are only two reasons I can see for making it a built-in.
|
|
|
|
The first is if it could be done much faster, which isn't the
|
|
|
|
case. The second is if it makes it significantly easier to
|
|
|
|
write code. The introduction of sets.py eliminates this
|
|
|
|
situation since creating a sequence without duplicates is just
|
|
|
|
a matter of choosing a different data structure: a set instead
|
|
|
|
of a list.
|
2002-11-06 00:41:32 -05:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
As described in PEP 218, sets are being added to the standard
|
|
|
|
library for Python 2.3.
|
2002-11-06 00:41:32 -05:00
|
|
|
|
|
|
|
|
2001-09-07 18:40:38 -04:00
|
|
|
Abstract
|
2017-01-07 13:33:00 -05:00
|
|
|
========
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
This PEP proposes adding a method for removing duplicate elements to
|
|
|
|
the list object.
|
2001-09-07 18:40:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
Rationale
|
2017-01-07 13:33:00 -05:00
|
|
|
=========
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
Removing duplicates from a list is a common task. I think it is
|
|
|
|
useful and general enough to belong as a method in list objects.
|
|
|
|
It also has potential for faster execution when implemented in C,
|
|
|
|
especially if optimization using hashing or sorted cannot be used.
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
On comp.lang.python there are many, many, posts [1]_ asking about
|
|
|
|
the best way to do this task. It's a little tricky to implement
|
|
|
|
optimally and it would be nice to save people the trouble of
|
|
|
|
figuring it out themselves.
|
2001-09-07 18:40:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
Considerations
|
2017-01-07 13:33:00 -05:00
|
|
|
==============
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
Tim Peters suggests trying to use a hash table, then trying to
|
|
|
|
sort, and finally falling back on brute force [2]_. Should uniq
|
|
|
|
maintain list order at the expense of speed?
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
Is it spelled 'uniq' or 'unique'?
|
2001-09-07 18:40:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
Reference Implementation
|
2017-01-07 13:33:00 -05:00
|
|
|
========================
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
I've written the brute force version. It's about 20 lines of code
|
|
|
|
in listobject.c. Adding support for hash table and sorted
|
|
|
|
duplicate removal would only take another hour or so.
|
2001-09-07 18:40:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
References
|
2017-01-07 13:33:00 -05:00
|
|
|
==========
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
.. [1] http://groups.google.com/groups?as_q=duplicates&as_ugroup=comp.lang.python
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
.. [2] Tim Peters unique() entry in the Python cookbook::
|
|
|
|
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560/index_txt
|
2001-09-07 18:40:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
Copyright
|
2017-01-07 13:33:00 -05:00
|
|
|
=========
|
2001-09-07 18:40:38 -04:00
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
This document has been placed in the public domain.
|
2001-09-07 18:40:38 -04:00
|
|
|
|
|
|
|
|
2017-01-07 13:33:00 -05:00
|
|
|
|
|
|
|
..
|
|
|
|
Local Variables:
|
|
|
|
mode: indented-text
|
|
|
|
indent-tabs-mode: nil
|
|
|
|
fill-column: 70
|
|
|
|
End:
|