bobhig

Sorted_list

May 23rd, 2021
610
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Sort a list of student scores
  2.  
  3. scores = '54 - Alice,35 - Bob,27 - Carol,27 - Chuck,05 - Craig,30 - Dan,27 - Erin,77 - Eve,14 - Fay,20 - Frank,48 - Grace,61 - Heidi,03 - Judy,28 - Mallory,05 - Olivia,44 - Oscar,34 - Peggy,30 - Sybil,82 - Trent,75 - Trudy,92 - Victor,37 - Walter'
  4.  
  5. scores = scores.split(',')
  6.  
  7. for x in sorted(scores):
  8.     print(x)
  9.    
  10. #now print in reverse order
  11.  
  12. for x in reversed(sorted(scores)):
  13.     print(x)
  14.    
RAW Paste Data