Toooo slow.... - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Toooo slow.... (/thread-31159.html) |
Toooo slow.... - Radez - Nov-25-2020 Hi, My code is meant to go through list 't' and check if any object from it is smaller than the first object in list 'a', if there is one, than it changes the value to '100001' which is just a sign to me that its already used, and than it goes to the next object in list 'a' and does that until it goes through the whole list 'a'. Also the values from list 't' can only be used once each. Does anyone have an idea or a clue on how to optimize or speed up this code? for k in range(m): u=0 for u in range(n): if t[u]<a[k]: t[u]=100001 a[k]=100001 l+=1 break RE: Toooo slow.... - perfringo - Nov-25-2020 Start with clarity in mind. Your problem description:
I may only assume what you want to accomplish.... like finding minimum value in list 'a' and then checking which items in list 't' are smaller of it. RE: Toooo slow.... - deanhystad - Nov-25-2020 This is a test to see if you think things through before you start coding. min(a) removes the outer loop and will speed things greatly |