-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

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
user5507798
  • 57
  • 1
  • 8

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
  • 2,060
  • 2
  • 10
  • 25