12. Lists and Functions


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

print join_strings(n)

""""Hey Guys I've already completed the course I just wanted to figure out why the .append() method doesn't seem to work. Please Help."""


your result is empty string and you are appending empty string. Maybe you want to append i?


Thanks! Have just tried your method. But now its giving me this error:

Oops, try again. join_strings(['x', 'y', 'z', 'a']) returned '' instead of 'xyza'.


Tried it on IDLE too


append to result and not to words:



You need to append your i to result to get string



I've tried the results.append(i) method getting new error. @knezknele @tomaszd7

Oops, try again. join_strings(['x', 'y', 'z', 'a']) resulted in an error: 'str' object has no attribute 'append'


And also trying to run this other code on IDLE please tell me what I'm dooing wrong. I want to create a single list out of the sub lists.

n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]

def flatten(lists):
results = []
for lists in n:
for numbers in lists:
result += lists[numbers]
return results

print flatten(n)


your variable is called result not results


Haha yea that was a typo. I wrote result but still gave same error.


Found solution to that other piece of code of concatenating sub lists. but still stuck on joining the strings. @knezknele @tomaszd7


Oh, your return should be outside of the loop and you can't append string, it just works for list. You can try something like this

result += words[i]


Thank you very much! @knezknele