Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dictionary custom ordering

Status
Not open for further replies.

ceco

IS-IT--Management
Oct 16, 2002
229
BG
Hallo,
I am new to python, and I am trying to do something that I am used to do in PHP (so the promlem may be conceptional) and search quite a lot in google, but :-( no efect

I have configuration file with something like that

MENU_ELEMENTS = {
'menu1': {'id': '10', 'name': 'Some name'},
'menu2': {'id': '11', 'name': 'Some other name'},
'menu3': {'id': '12', 'name': 'Some other other name'},
}

I want to iterate them in the order I put them in, but the result always is the same without the order I put them
I use

>>> MENU_ELEMENTS = {
... 'menu2': {'id': '11', 'name': 'Some other name'},
... 'menu1': {'id': '10', 'name': 'Some name'},
... 'menu3': {'id': '12', 'name': 'Some other other name'},
... }
>>> for MENU_ELEMENT_K, MENU_ELEMENT_V in MENU_ELEMENTS.iteritems():
... print MENU_ELEMENT_K, MENU_ELEMENT_V
...
menu2 {'id': '11', 'name': 'Some other name'}
menu3 {'id': '12', 'name': 'Some other other name'}
menu1 {'id': '10', 'name': 'Some name'}
>>> MENU_ELEMENTS = {
... 'menu1': {'id': '10', 'name': 'Some name'},
... 'menu2': {'id': '11', 'name': 'Some other name'},
... 'menu3': {'id': '12', 'name': 'Some other other name'},
... }
>>> for MENU_ELEMENT_K, MENU_ELEMENT_V in MENU_ELEMENTS.iteritems():
... print MENU_ELEMENT_K, MENU_ELEMENT_V
...
menu2 {'id': '11', 'name': 'Some other name'}
menu3 {'id': '12', 'name': 'Some other other name'}
menu1 {'id': '10', 'name': 'Some name'}

is my idea totaly wrong, and how can I achieve the desired
thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top