-2

I do not understand why this code does not return the list ordered:

A = {2:'a', 1: 'b', 3:'c'} 

R = list(a.keys()).sort()

In fact it does not return anything. I know I could do it in other ways like sorted(a.keys).

Thanks

U12-Forward
  • 65,118
  • 12
  • 70
  • 89
user5507798
  • 57
  • 1
  • 7

1 Answers1

1

sort() does in-place changes to the list. What you can do is create a variable to store the keys and then sort it.

R = list(a.keys())
R.sort()

Use R = sorted(list(a.keys())) instead, as sort() serve as an in-place function

PIG208
  • 1,628
  • 1
  • 8
  • 20