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.

Ma0
  • 15,057
  • 4
  • 35
  • 65
T.DOGG
  • 223
  • 2
  • 7

1 Answers1

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']]
Yarnspinner
  • 852
  • 5
  • 7
  • Thanks for the heads up. Didn't realize it was a numpy array. At least, im assuming np refers to numpy – Yarnspinner Jun 21 '16 at 13:07
  • 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? – T.DOGG Jun 21 '16 at 13:29
  • 1
    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 – Yarnspinner Jun 21 '16 at 13:39
  • We, accidentaly put a space in before M. Thanks man. – T.DOGG Jun 21 '16 at 14:00
  • No problem, glad i could help! – Yarnspinner Jun 21 '16 at 14:02