Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Creating and sorting a 2D array

How do you create a double-array in Sage (first component string, second component int)? And, how do you sort the double-array based on the value of the second component?

Right now, our code looks like:

G0 = []
pop = 0
while pop<1000:
    G0.append(randomWord())
    pop+=1

G0_fit = []
for i in range (0,1000):
    G0_fit.append(FitFunc(G0[i]))

tempList = sorted(G0_fit)
cutoff = tempList[400]

inter = []
for i in range (0, 1000):
    if G0_fit[i]<=cutoff:
        inter.append(G0[i])

We want to avoid the "cutoff=tempList[400]" and following loop, and just sort both G0 and G0_fit in one step.