thanks very much indeed for your help is there a better way to do this (python3) newby

kshitij kraranke at gmail.com
Tue Feb 24 11:42:47 EST 2009


On Feb 24, 6:29 am, "Rhodri James" <rho... at wildebst.demon.co.uk>
wrote:
> On Mon, 23 Feb 2009 23:33:31 -0000, Gary Wood <woody... at sky.com> wrote:
> > '''exercise to complete and test this function'''
> > import string
> > def joinStrings(items):
> >     '''Join all the strings in stringList into one string,
> >     and return the result. For example:
> >     >>> print joinStrings(['very', 'hot', 'day'])
> >     'veryhotday'
> >     '''
> >     for i in items:
> >        return (''.join(items))
>
> As I'm sure your teacher will point out, this is sub-optimal :-)
> That for-loop isn't doing anything, because you always return
> out of it at the first iteration.
>
> I suspect that you're expected to concatenate the strings
> together by hand and return the resulting string once you've
> done them all.  Trying writing it that way.
>
> PS: it helps a lot if what you say in the doc string matches
> what you write in the rest of the code.  In this case you
> call your input string "items", but then say "Join all the
> strings in *stringList*..."
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses

Here is another way of doing this:

print ('very' + 'hot' + 'day')

Hope this helps.



More information about the Python-list mailing list