I'm working my way through CodeAcademy and I have a question that's going unanswered there. The assignment is to take a list of lists and make a single list of all its elements. The code immediately below is my answer that worked. But what I don't understand is why "item" is treated as elements in a list for that code whereas (see comment continued below)...
m = [1, 2, 3]
n = [4, 5, 6]
o = [7, 8, 9]
def join_lists(*args):
new_list = []
for item in args:
new_list += item
return new_list
print join_lists(m, n, o)
...the "item" in the code below is treated as the whole list instead of elements in a list. The code below gives the ouput:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
I also tried to use: new_list.append(item[0:][0:]) thinking it would iterate through the index and sub-index but it gave the same result. I just don't understand how this is being interpreted.
m = [1, 2, 3]
n = [4, 5, 6]
o = [7, 8, 9]
def join_lists(*args):
new_list = []
for item in args:
new_list.append(item)
return new_list
print join_lists(m, n, o)
Also, I know I could add another for-loop to the code above, and I get why that works, but I still don't understand with one line of difference why Python interprets these differently.