Close
Close

this is giving me 'None' as output instead of the reverse list of sorted(score)

   Mudit Gupta , IIT Kanpur


score = {40:"x",30:"y",50:"z",45:"a"}
print(sorted(score).reverse())


Answers

  •   

    it is because reverse() doesnt return the reversed list , it modifies the existing list,try this instead

    score = {40:"x",30:"y",50:"z",45:"a"}

    sorted_score= sorted(score)
    sorted_score.reverse()

    print(sorted_score)



Ask Yours
Post Yours
Write your answer