Im trying to print out all elements in a list, in Python, after I´ve appended one list to another. The problem is that it only prints out every element when I use PRINT inst
return
means end of a function. It will only return the first element of the list.
For your print
version, a.append(b)
makes a = [1,2,3,4,[1,2,3]]
so you will see the elements before None
. And the function returns nothing, so print union(a, b)
will print a None.
I think you may want:
def union(a, b):
a.extend(b)
return a
Or
def union(a, b):
return a + b