Using Strings in Lists in Functions


#1


I dont know what im doing wrong, be a doll and help me.
Oops, try again. join_strings(['x', 'y', 'z', 'a']) returned '' instead of 'xyza'


n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
    result = ""
    for x in range(len(words)):
        words.append(result)
    return result
print join_strings(n)


#2

.append() is designed to append items to a list, not to a string.

to join strings see this example:

test1 = "hello"
test2 = test1 + " world"
print test2 # will print hello world

now try to apply this logic to your program


#3

Im still not getting it. now its saying, cant assign function call


#4

Can you post your new code?


#5

n = ["Michael", "Lieberman"]

Add your function here

def join_strings(words):
result = ""
for item in words:
result.append(words) += item
return result

print join_strings(n)


#6

append() won't work for strings. remove the append() alltogether.


#7

yeah i just realized that. got it


#8

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