0

We want to sort "names" alphebeticaly while sill making sure the appropriate grade (grraides) are given to the right student.

print("List of grades are:")
grraids=computeFinalGrade(pure_data)
kn=np.column_stack((names,grraids))
for names in sorted(kn):
    print(kn)

enter image description here

We get that out, but would very much like those names to be in alphebetical order, but keeping the function general.

0

1 Answer 1

1

Edit: Sorry, didn't realize it was a numpy array, code has been changed accordingly. However, it still assumes the student name is always in the same place. (first spot)

import numpy as np
grades = np.array([["B",10],["C",8],["A",3]])
print grades
grades.sort(axis=0)
print grades

Output:

[['B' '10']
 ['C' '8']
 ['A' '3']]
[['A' '10']
 ['B' '3']
 ['C' '8']]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the heads up. Didn't realize it was a numpy array. At least, im assuming np refers to numpy
I get the return input TypeError: unorderable types: float() > str(). When i write grades.sort(axis=1), i sort the values after the smallest to largest grade, but when i write grades.sort(axis=0) it returns the type error. Any sugestions?
It seems like you have mixed numbers and strings in the first position of the pairs of (students,results). I.e. Theres a pair somewhere which is something like[2.0,"b"]. I would try print kn to have a look at the data first to make sure the first column is only names
We, accidentaly put a space in before M. Thanks man.
No problem, glad i could help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.