Alphabetized dictionary listings

Ken Power iam at not.you
Wed Nov 17 15:23:51 CET 1999


Why does this occur? More to the point, how can I have the print-out
be in alphabetical order?

>>> myList = ['Abel', 'Dexter', 'Francis', 'Matthew', 'Samantha', 'Tyrone']
>>> myDict = {}
>>> for name in myList:
	myDict[name] = 0
	
	
>>> for key in myDict.keys():
	print key
	
	
Tyrone
Samantha
Francis
Abel
Matthew
Dexter


Again, how can I have the printout be in Alphabetical order? I also
noticed that if I fed values to myDict[key] from another list, that
was constructed so it's values would match the keys in myDict, that
the values would be assigned to the wrong keys:

>>> myList2 = ['lebA', 'rexteD', 'sicnarF', 'wehttaM', 'ahtnamaS', 'enoryT']
>>> var = 0
>>> for key in myDict.keys():
	myDict[key] = myList2[var]
	var = var + 1

>>> for key in myDict.keys():
	print key, myDict[key]
	
	
Matthew ahtnamaS
Francis sicnarF
Abel wehttaM
Samantha rexteD
Dexter enoryT
Tyrone lebA
As you can see the assignements are in correct.  Well, if this is
understandable, could someone offer some insight? Thank you.

Ken
--------------------------------
Ken Power
uncle_wiggly at bigfoot dot com
get that?
--------------------------------




More information about the Python-list mailing list