question about dictionaries

C

Chris

When you declare a dictionary, Python puts it in a different order than
the way you declare it:
{'<br>':'\n', '\n':''}

Is there a way to stop this behavior? I want to process this dictionary
in the order it's in, element by element. I'm running Python 2.3, if
that helps.

Thanks for any help!
 
P

Paul Rubin

Chris said:
Is there a way to stop this behavior? I want to process this dictionary
in the order it's in, element by element. I'm running Python 2.3, if
that helps.

You want a list not a dictionary.
 
B

Brett Hoerner

Chris said:
Is there a way to stop this behavior? I want to process this dictionary
in the order it's in, element by element. I'm running Python 2.3, if
that helps.

As said previously, you either want a list (which are ordered), or an
ordered-dictionary (not a Python native type, see
http://www.voidspace.org.uk/python/odict.html)

dict datatypes do not maintain any specific order and aren't really
meant to, they're just handy, 'fast' hash lookups.

Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top