"David" <[EMAIL PROTECTED]> wrote

I have two solutions:

a)
(string.capitalize(s1) + " " + string.capitalize( s2) + "  " ) * 3
b)
"%s %s " % (string.capitalize(s1), string.capitalize(s2)) * 3

Both seem to work, but they seem overly complex. Where could I improve?

Personally I'd go with b but avoid the string module and add an rstrip():

("%s %s " % (s1.capitalize(),s2.capitalize()) * 3).rstrip()

Or another approach:

"%s %s %s %s %s %s" % ((s1.capitalize(),s2.capitalize())*3)
'Foo Bar Foo Bar Foo Bar'

But the first is more flexible IMHO.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to