M
Marcio Rosa da Silva
Hi!
In dictionaries, unlinke lists, it doesn't matter the order one inserts
the contents, elements are stored using its own rules.
Ex:
{1: 2, 3: 4}
So, my question is: if I use keys() and values() it will give me the
keys and values in the same order?
In other words, it is safe to do:
to exchange keys and values on a dictionary? Or I can have the values
and keys in a different order and end with something like this:
{2: 3 , 4: 1}
instead of:
{2: 1, 4: 3}
For this example it works as I wanted (the second output), but can I
trust this?
Also, if someone has a better way to exchange keys and values in a dict,
I would like to learn.
Thanks!
Marcio
In dictionaries, unlinke lists, it doesn't matter the order one inserts
the contents, elements are stored using its own rules.
Ex:
{1: 2, 3: 4}
So, my question is: if I use keys() and values() it will give me the
keys and values in the same order?
In other words, it is safe to do:
to exchange keys and values on a dictionary? Or I can have the values
and keys in a different order and end with something like this:
{2: 3 , 4: 1}
instead of:
{2: 1, 4: 3}
For this example it works as I wanted (the second output), but can I
trust this?
Also, if someone has a better way to exchange keys and values in a dict,
I would like to learn.
Thanks!
Marcio