[Tutor] newbie question

Trilok Khairnar trilokgk at gmail.com
Mon Oct 15 17:56:55 CEST 2007


> With this, and if you want to use your formatted print statements instead
of the join, you could use something like
> print "Specials: %s %s %s" % tuple(menu_specials.values()) which turns the
output of menu_specials.values() (a list) into a tuple.
> Disadvantage is that you'll need to know the number of values in advance,
for the number of '%s' in your format string (alternatively,
> you could build up the format string in a loop first). Note that values()
bypasses the above list comprehensions entirely.

With the following, you can do fine without knowing the length in advance.

tpl = tuple(menu_specials.values())
Print "Specials: " + ' '.join(["%s"*len(tpl)]) % tpl

Thanks,
Trilok.




More information about the Tutor mailing list