[Tutor] Poor style to use list as "array"?

Alan Gauld alan.gauld at btinternet.com
Mon Jul 6 01:16:26 CEST 2009


"Angus Rodgers" <angusr at bigfoot.com> wrote 

> as keys?  Is it possible to guarantee a sequence in which the keys
> of a dictionary are iterated through? 

Indirectly yes:

for key in sorted( dct ):
    print key

I would definitely tend to go with a dictionary for the 
denominations/values in this case  (Actually I'd probably 
go for a class but that's another ball game entirely!)


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list