Using strings in lists in functions


#1




Traceback (most recent call last):
File "python", line 10, in
File "python", line 4, in join_strings
AttributeError: 'str' object has no attribute 'append'


The stings should get concatenated and printed.


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


print join_strings(n)


#2

words is not a dictionary with arbitrary strings as keys. You are using a look-up list which iterates over strings, not indices.

result = result + i

#3

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