Fast Efficient way to transfer an object to another list
Daniel Stutzbach
daniel at stutzbachenterprises.com
Sat May 1 11:57:56 EDT 2010
On Fri, Apr 30, 2010 at 9:16 PM, Jimbo <nilly16 at yahoo.com> wrote:
> Hello I have a relatively simple thing to do; move an object from one
> to list into another. But I think my solution maybe inefficient &
> slow.
>
Removing an item from a list is O(n) on average, so it's going to be a bit
slow any way you slice it (unless you only remove from the end of the list
which is O(1)).
Can you tell us more about why you're using a list? If the order of the
items doesn't matter, you may be able to use a set().
If the order matters, how is the list ordered? If we know how the list is
ordered, we may be able to help you come up with a clever way to remove an
item cheaply.
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100501/aa864c07/attachment-0001.html>
More information about the Python-list
mailing list