Using strings in lists in functions


I did this using the first method mentioned in the exercise i.e. using "for item in words:" But when I tried with the second method i.e. "for item in range(len(words)):". It does not work.

I thought you can't modify list elements using the first method but you can using the second method. This exercise proved otherwise.

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

print join_strings(n)


you can use range(), that is fine. But then you should retrieve the index from the right list. Currently you retrieve items from result, which is an empty string

the words you want to retrieve are in words (function parameter), so you should use words[index]


Thanks! :slight_smile: