Skip to content

Instantly share code, notes, and snippets.

@olivx
Created January 22, 2019 13:14
Show Gist options
  • Save olivx/1c74e5a1efb08dc488c3e9342b96af53 to your computer and use it in GitHub Desktop.
Save olivx/1c74e5a1efb08dc488c3e9342b96af53 to your computer and use it in GitHub Desktop.
ordenação alfabética de um dicionario removendo acentos
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