Created
January 22, 2019 13:14
-
-
Save olivx/1c74e5a1efb08dc488c3e9342b96af53 to your computer and use it in GitHub Desktop.
ordenação alfabética de um dicionario removendo acentos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unicodedata import normalize | |
data = {} | |
for qs in queryset: | |
# remove os ascentos | |
target = normalize('NFKD', qs).encode('ASCII','ignore').decode('ASCII').title().strip() | |
data[target] = target | |
# orderna os items de um dict ou list | |
data_sorterd = sorted(data.items(), key=lambda kv: kv[1]) | |
# order dict para manter a ordenação. | |
return JsonResponse(OrderedDict((y, x) for x, y in data_sorterd)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment