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
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
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