Dictionaries

Marcus Vinicius Laranjeira m.laranjeira at datacraft.com.br
Tue Jul 16 17:15:34 EDT 2002


Hi folks,

I got a big doubt... how python manages data in dictionaries ? for example:

Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> dic = { 'R1': 1}
 >>> dic
{'R1': 1}
 >>> dic['R2'] = 3
 >>> dic
{'R1': 1, 'R2': 3}
 >>> dic['R4'] = 2
 >>> dic
{'R4': 2, 'R1': 1, 'R2': 3}
 >>>

I created a dictionary with one key 'R1' and a value of 1. Then, I inserted 
a new item with a key 'R2' and a value of 3... It worked like I though it 
would: appended the new item at the end of the dictionary.

But why when I insert a new item with a key 'R4' and a value of 2 it 
inserts it in the begining of the dictionary ????????

How can I change the order of the items in a dictionary !?!?!?

Thanks a lot,

Marcus






More information about the Python-list mailing list