[Tutor] Joining all strings in stringList into one string
Jordan
wolfrage8765 at gmail.com
Sat Jun 2 13:39:40 CEST 2012
On 05/30/2012 06:21 PM, Akeria Timothy wrote:
> Hello all,
>
> I am working on learning Python(on my own) and ran into an exercise
> that I figured out but I wanted to know if there was a different way
> to write the code? I know he wanted a different answer for the body
> because we haven't gotten to the ' '.join() command yet.
>
> This is what I have:
>
> def joinStrings(stringList):
> string = []
> for string in stringList:
# Here you never used the string variable so why have a for statement?
> print ''.join(stringList)
#Another version might look like this:
def join_strings2(string_list):
final_string = ''
for string in string_list:
final_string += string
print(final_string)
return final_string
# Tested in Python 3.2
join_strings2(['1', '2', '3', '4', '5'])
>
>
> def main():
> print joinStrings(['very', 'hot', 'day'])
> print joinStrings(['this', 'is', 'it'])
> print joinStrings(['1', '2', '3', '4', '5'])
>
> main()
>
>
> thanks all
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120602/1e440f5e/attachment.html>
More information about the Tutor
mailing list