16/18 list and functions help!


#1

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!


#2

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.

REPLACE THIS:
result += n
WITH THIS:
result += words[n]


#3

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

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=
    #like
    print my_list[index_nr]

A discussion/opinion
http://stackoverflow.com/questions/19184335/is-there-a-need-for-rangelena

or from
== the Book ==
https://docs.python.org/2/library/functions.html
https://docs.python.org/2/library/functions.html#len


#4

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