Can I replace this for loop with a join?

Paul Watson paul.hermeneutic at gmail.com
Sun Jun 21 15:57:34 EDT 2009


On Mon, 2009-04-13 at 17:03 +0200, WP wrote:
> Hello, I have dictionary {1:"astring", 2:"anotherstring", etc}
> 
> I now want to print:
> "Press 1 for astring"
> "Press 2 for anotherstring" etc
> 
> I could do it like this:
> dict = {1:'astring', 2:'anotherstring'}
> for key in dict.keys():
>      print 'Press %i for %s' % (key, dict[key])
> 
> Press 1 for astring
> Press 2 for anotherstring
> 
> but can I use a join instead?
> 
> Thanks for any replies!
> 
> - WP

In addition to the comments already made, this code will be quite broken
if there is ever a need to localize your package in another language.




More information about the Python-list mailing list