1 Replies - 1137 Views - Last Post: 01 May 2010 - 02:45 PM Rate Topic: -----

#1 gretty  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 123
  • Joined: 25-May 09

Faster Simplier Way to Move Object into List

Posted 29 April 2010 - 08:11 PM

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 solution?)

class stock:

    code = "NULL"
    price = 0


stock_list1 = []
stock_list2 = []

def transfer_stock(stock_code, old_list, new_list):
    """ Transfer a stock from one list to another """
    # is there a more efficient & faster way to 

    index = 0
    
    for stock in old_list:

        temp_stock = stock

        if temp_stock.code == stock_code:
            new_list.append(temp_stock)
            del old_list[index]
        index += 1

    return new_list


Is This A Good Question/Topic? 0
  • +

Replies To: Faster Simplier Way to Move Object into List

#2 Perl and Python  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 01-February 10

Re: Faster Simplier Way to Move Object into List

Posted 01 May 2010 - 02:45 PM

Is the original data from an external source i.e. a file and are you moving the data within python? Sorry about my confusion but I do quite understand what you are asking.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1