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

Rhodri James rhodri at wildebst.demon.co.uk
Mon Feb 23 20:29:17 EST 2009


On Mon, 23 Feb 2009 23:33:31 -0000, Gary Wood <woodygar 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



More information about the Python-list mailing list