3
The following script sorts a dictionary:
d = {'a': 10, 'g': 15, 'c': 67, 'z': 90, 'e': 144}
ordenada = list(d.keys()) # gera uma lista das chaves do dicionário (protegida por uma tupla)
ordenada.sort() # ordena a lista de chaves
for chave in ordenada:
print(chave, '=', d[chave], end=', ') # mapeia os valores com as chaves ordenadas
I tried this way too and I couldn’t:
ordenada = list(d.keys()).sort()
print(ordenada) # está retornando None
I wanted to understand why by applying the method sort()
on the same line it is returning None
. I thought the object orientation paradigm would be applied here, where I first transform d.keys()
in an object list
to then put it in order. Does it make sense?
Taking advantage, if you can, to explain the meaning of None in some other more elaborate case.
This answers your question? "Sort" method returning only "None", what is the reason?
– AlexCiuffa