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


#1



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.append(i)
        else:
            result = result[0] + i
    return result
    # Add your function here



print join_strings(n)


#2

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


#3

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


#4

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


#5

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 []..so .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:


#6