Using strings in lists in functions


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/3/5?curriculum_id=4f89dab3d788890003000096


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)


#2

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]


#4

Thanks! :slight_smile:


#5