Ask Your Question

Creating and sorting a 2D array

asked 2013-02-09 10:48:36 -0500

jquigley gravatar image

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_fit = []
for i in range (0,1000):

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

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

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-02-09 13:33:53 -0500

ppurka gravatar image

Look at the python documentation, especially at the key function.

edit flag offensive delete link more


Sorry for the delayed response. We gave it a try, and it's definitely a much more natural way to sort. Thanks!

jquigley gravatar imagejquigley ( 2013-02-15 15:13:05 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-02-09 10:48:36 -0500

Seen: 145 times

Last updated: Feb 09 '13