Using strings in lists in functions what am I doing wrong?


Traceback (most recent call last):
File “python”, line 8, in
File “python”, line 6, in join_strings
TypeError: cannot concatenate ‘str’ and ‘int’ objects

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


using range() will produce a list of integers which you can use as indexes to get values from words list, which you can then add to result. Or just get rid of range so you get the values/items from the list directly


result = result + words[i]

got it, thanks :slight_smile: