Using strings in lists and functions - I get the right output but it tells me I'm wrong?!


Can someone tell me why this is wrong? I'm getting the correct output ('MichaelLiebermann'), but I get the Console tells me the exercise is still wrong.

I get this error message: Oops, try again. join__strings(['x', 'y', 'z', 'a']) returned 'xa' instead of 'xyza'

Can anyone tell me why this is wrong?

n = ["Michael", "Lieberman"]

def join_strings(words):
    result = []
    for i in words:
        if i == words[0]:
            result = result[0] + i
    return result
    # Add your function here

print join_strings(n)


your function should also work for ['x', 'y', 'z', 'a']


But why doesn't my code work for those? It should as far as I can see :frowning:


because result should be a string, and you simply iterate over words and add to result


haha ohhhh now I see. I started using result as a string "", but then tried using the .append() function with it which doesn't work with strings.

So I made result a list [] .append worked but the output was wrong :slight_smile:
now I changes result back to a string and used += instead of .append()

Thanks a lot :wink: