0

I'll try and reexplain my question down here. I'm trying to create a program which will allow the user to input a players name and their jersey number which will put it into a dictionary. The next function will read the dictionary and print out Player Name: NAME, Jersey Number: NUMBER where name is the name in the dictionary and number is their corresponding jersey number. I can't figure out how to make it so that the names and corresponding jersey number are organized by the number. Here is what I have so far:

def print_roster(team):
   team1=sorted(team.values())
   for x in range(len(team)):
      print('Player Name: %s, Jersey Number: %d' % (NAME, team1[x]))
Simon Mengong
  • 2,625
  • 10
  • 22
David Fite
  • 13
  • 3
  • 1
    Possible duplicate of [How to sort a dictionary by value?](https://stackoverflow.com/questions/613183/how-to-sort-a-dictionary-by-value) – gommb Oct 26 '17 at 03:24

1 Answers1

1

You can try this:

def print_roster(team):
  for a, b in sorted(team.items(), key=lambda x:x[-1]):
     print(a, b)
Ajax1234
  • 69,937
  • 8
  • 61
  • 102