16/18 list and functions help!


Here is my code:
def join_strings(words):
result = ""
for n in range(len(words)):
result += n
return result

print join_strings(n)

Please Help!

Thanks in advance!


What you are doing wrong is that you're adding the variable n to results. n is a number in the range len(words), so I think your code is glitching out because you're trying to add a int to a string.

result += n
result += words[n]


If you have a =list=
you have a comma-, list of items =or= Elements

my_list = ["item0-Value","item1-Value","item2-Value"]


Now if you use a FOR-IN loop like

for item_value in my_list:
    # you will iterate over =my_list=
    # and at every iteration 
    # the VARIABLE =item_value= will get the  item-Value assigned....
    #iteration-1 ==> item_value = "item0-Value"
    #iteration-2 ==> item_value = "item1-Value"
    #iteration-3 ==> item_value = "item2-Value"
    print item_value


Now if you use a FOR-IN loop like

for index_nr in range( len(my_list)):
    # with range(len(my_list)) you will create a =list= [0,1,2]
    # and now the FOR-IN loop will iterate over this [0,1,2] list
    # iteration-1 ==> index_nr = 0
    # iteration-2 ==> index_nr = 1
    # iteration-3 ==> index_nr = 2
    # to get at the item_Value of the my_list Elements
    # you use the so-called =bracket-notation=
    print my_list[index_nr]

A discussion/opinion

or from
== the Book ==


THANK YOU!!! I spent so much time on this!