Re: Fast Efficient way to transfer an object to another list

2010-05-07 Thread Bryan
Gabriel Genellina wrote: > I'd do that in two steps: > > def transfer_stock(stock_code, old_list, new_list): >    # find the indexes to transfer >    indexes = [i for i,stock in enumerate(old_list) >               if stock.code==stock_code] >    # actually transfer them >    for index in reversed(i

Re: Fast Efficient way to transfer an object to another list

2010-05-04 Thread Gabriel Genellina
En Fri, 30 Apr 2010 23:16:04 -0300, Jimbo escribió: 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. Is there a faster better way to move my stock object from one list to another? (IE, without having to

Re: Fast Efficient way to transfer an object to another list

2010-05-02 Thread Bryan
Steven D'Aprano wrote: > The simplest way to speed the above code up is not to start from the > beginning each time. That requires two very small changes. And since > deletions from the front of the list are slow, MRAB's suggestion is also > a good idea. Those two speed-ups provide worst-case line

Re: Fast Efficient way to transfer an object to another list

2010-05-02 Thread Hans Mulder
Francesco Bochicchio wrote: Anyway i think that list.extract( old_list, predicate ) -> new_list would be a nice addition to the standard library You could use filter( predicate, old_list ) -> new_list -- HansM -- http://mail.python.org/mailman/listinfo/python-list

Re: Fast Efficient way to transfer an object to another list

2010-05-01 Thread Steven D'Aprano
On Sat, 01 May 2010 08:11:45 -0700, Francesco Bochicchio wrote: > On 1 Mag, 05:35, Steven D'Aprano > wrote: > > >> def transfer_stock(stock_code, old_list, new_list): >>     """ Transfer a stock from one list to another """ while True:  # >>     loop forever >>         try: >>             i = o

Re: Fast Efficient way to transfer an object to another list

2010-05-01 Thread Daniel Stutzbach
On Fri, Apr 30, 2010 at 9:16 PM, Jimbo 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

Re: Fast Efficient way to transfer an object to another list

2010-05-01 Thread Francesco Bochicchio
On 1 Mag, 05:35, Steven D'Aprano wrote: > > def transfer_stock(stock_code, old_list, new_list): >     """ Transfer a stock from one list to another """ >     while True:  # loop forever >         try: >             i = old_list.index(stock_code) >         except ValueError: >             # not fo

Re: Fast Efficient way to transfer an object to another list

2010-05-01 Thread MRAB
Tim Chase wrote: On 04/30/2010 10:35 PM, Steven D'Aprano wrote: If you know there is one, and only one, item with that stock code: def transfer_stock(stock_code, old_list, new_list): """ Transfer a stock from one list to another """ i = old_list.index(stock_code) # search new_li

Re: Fast Efficient way to transfer an object to another list

2010-05-01 Thread Tim Chase
On 04/30/2010 10:35 PM, Steven D'Aprano wrote: If you know there is one, and only one, item with that stock code: def transfer_stock(stock_code, old_list, new_list): """ Transfer a stock from one list to another """ i = old_list.index(stock_code) # search new_list.append(old_list

Re: Fast Efficient way to transfer an object to another list

2010-04-30 Thread Steven D'Aprano
On Fri, 30 Apr 2010 19:16:04 -0700, Jimbo 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. Is > there a faster better way to move my stock object from one list to > another? (IE, without having

Re: Fast Efficient way to transfer an object to another list

2010-04-30 Thread Kushal Kumaran
On Sat, May 1, 2010 at 7:46 AM, Jimbo 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. Is there a faster better way to move my stock object from one > list to another? (IE, without having to u

Fast Efficient way to transfer an object to another list

2010-04-30 Thread Jimbo
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. Is there a faster better way to move my stock object from one list to another? (IE, without having to use a dictionary instead of a list or is that my only s