Using strings in lists in functions


I don't know?

Replace this line with your code. 
n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
    result = ""
    for words in words:
        result = words.append + result
        return result 

print join_strings(n)


Your for loop's variable should not be the same as the object being iterated over,

something else like will do,

for word in words:

And on this line you are to append the iterated values to your empty sring,




Your return statement should be on the same indentation level as your for loop,

for x in example:
    #some code
return #some code


I figured out that you can't use the .append with a string, and should use something like
result = result + i


You can also do something like this ...

result += word

... which is equivalent to ...

result = result + word

However, to combine a large number of str objects, it is more efficient to append them each into a list and then to use join to combine the items in the list into a unified str object.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.