[Tutor] outputting dictionary key/value pairs

Terence Lo tlo@alias.com
Wed Aug 6 18:11:05 EDT 2003


hi,

 supoose i create a dictionary of the form:

dict = {"d1": "a", "d2": "b", "d3": "c"}

why is it that when i loop through the dictionary,

eg.

for k,v in dict.items():
	print k,v


the dictionary items aren't output in the order they appear in the
dictionary.  they seem to be returned in an arbitrary order.

is there a quick way to loop through the dict and output the contents in
order?  namely  d1 .. d2.. d3 ?

thx in advance.

t





More information about the Tutor mailing list