Using strings in lists in functions


Traceback (most recent call last):
File "python", line 10, in
File "python", line 7, in join_strings
TypeError: 'list' object is not callable

n = ["Michael", "Lieberman"]
# Add your function here

def join_strings(words):
    for i in range(len(words)):
        result= result + words(i)
    return result

print join_strings(n)


Let's go through this using the errors indicated.

Your use of the len and range in-built here

is not cool. You could simply for loop i in words.

for i in words:

Then, go on to

result += i


result = result + i

You should look at this Built-in Functions


If you're using the range(len(words)) option for doing this, then you need to use square brackets in words[i] instead of parentheses:

for i in range(len(words)):
    result += words[i]
return result


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