Jump to content

ordenação de dicionarios


mymind

Recommended Posts

Boas

uma vez mais trago um novo pedido de ajuda ....

"""

um programa que mostre ao utilizador os elementos de um dicionário

(chave,valor) ordenados pelo valor.

Exemplo:

Input={âaâ: 1,âbâ: 7,âcâ: 3,âdâ: -2,âeâ: 5,âfâ: -6,âgâ: 3.5}

Output:[(âfâ, -6), (âdâ, -2), (âaâ, 1), (âcâ, 3), (âgâ, 3.5), (âeâ, 5), (âbâ, 7)].

"""

def ordena_valor():

    Input={'a':1,'b':7,'c':3,'d':-2,'e': 5,'f':-6,'g': 3.5}

    new_input=Input.copy()

    #print new_input

    Input=sorted(Input.values())

    #print Input

    resultado= {}

   

    for i in Input:

        for item in new_input:

            if item==i:

                resultado[item]=i

    print resultado

           

alguem me pode dar umas dicas de como por isto a rolar...

tank s ? 😄

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.