[Tutor] newbie question
Luke Paireepinart
rabidpoobear at gmail.com
Mon Oct 15 18:33:07 CEST 2007
Trilok Khairnar wrote:
>> 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
>
I don't see the point of building a format string and then substituting
for it.
Why not just do:
print "Specials: " + ' '.join(menu_specials.values())
-Luke
More information about the Tutor
mailing list