Hello, I'm posting this code so that maybe it will help someone else in the future. I spent about a week trying to figure this out, and Google searches were not helping. Hopefully anyone else wondering about this will see this post on a Google result.
The program I finished writing was to simulate memory allocation, using schemes called first fit and best fit. I had two lists: jobSize (how big the job was) and length (how long the job stays active). For best fit, you must sort the job sizes, and I was having trouble keeping track with which item in the length list went to which jobSize item.
Anyway, if that made sense, here's what I did to sort the length list according to how the jobSize list was sorted...
sortJobSize = sorted(jobSize)
a=0
while a<len(length):
n=0
while n < len(length):
if jobSize[n] == sortJobSize[a]:
length[a] = length[n]
n+=1
a+=1
As you can see, it's very simple and I'm amazed it took me so long to hammer out a working algorithm. Basically, it will take one item from jobSize at a time and compare it to each item in the sorted list. For every item that matches, it will change the location of length's item according to the index of sortJobSize. Hope this helps someone!