 # Using two lists as two arguments in a function

Hi! Anybody know how to solve this?
m = [1, 2, 3]
n = [4, 5, 6]

def join_lists(x,y):
result=0
for i in range(len(x,y)):
result=result+x[i]+y[i]
return result
print join_lists(m, n)

# You want this to print [1, 2, 3, 4, 5, 6]

hi why dont you do this part

``````def join_lists(x,y):
result=0
for i in range(len(x,y)):
result=result+x[i]+y[i]
return result
``````

like that

``````
def join_lists(x, y) :
result = x + y
return result
``````
1 Like

can anyone pls tell me whats wrong here. Thank you

HI I think that you should return inside the function `join_list()` the argument `x and y`

``````def join_lists(x, y):
return x + y
``````
1 Like

Hi All,

I have used the below code and it works fine,

m = [1, 2, 3]
n = [4, 5, 6]

def join_lists(x, y):
All =
for i in range(len(x)):
mm = x
for i in range(len(y)):
mmm = y
All = mm + mmm
return All
print join_lists(m, n)

# mm and mmm are variables that I have added to help me.

1 Like

You can also have your result like this and it works:

m = [1, 2, 3]
n = [4, 5, 6]

def join_lists(x, y):
result =
for i in x:
k1 = x
for i in y:
k2 = y
result = k1 + k2
return result
print join_lists(m, n)

2 Likes

You can also use this;

def join_lists(x, y):
result = 0
for i in (x,y):
result = x+y
return result

3 Likes

I did it like this (without result=) to make it shorter:

m = [1, 2, 3]
n = [4, 5, 6]

def join_lists(x, y):
for i in (x,y):
result = x+y
return result

print join_lists(m, n)

1 Like