21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Respostas dos exercícios II 339

# Conta

resp = {}

for palavra in palavras:

resp[palavra] = resp.get(palavra, 0) + 1

saida = resp.items()

# Ordena

def cmp(x, y):

return x[-1] - y[-1]

saida.sort(cmp=cmp, reverse=True)

# Imprime

for k, v in saida:

print k, '=>', v

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!