Can I replace this for loop with a join?

WP no.i.dont at want.mail.from.spammers.com
Mon Apr 13 11:03:17 EDT 2009


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



More information about the Python-list mailing list