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
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
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
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
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
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
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
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
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
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
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
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
12 matches
Mail list logo