Sebastian Machado
Sebastian Machado

Reputation: 11

How to sort numbers in two lists using FOR loop

num1 = [1, 3, 5]
num2 = [2, 4, 6]

I have these two lists and need to use a FOR-Loop to organize them so that the print statement prints out the values like this:

1
2
3
4
5
6

I have tried this: for value in num1 and num2:

if num1[0] > num2[0]:
    print num1
else: 
    print num2

Nothing I have tried has worked :( This is my first coding class pls help

Upvotes: 0

Views: 69

Answers (3)

karthik reddy
karthik reddy

Reputation: 41

x=[1,3,5]
y=[2,4,6]
z=x+y
z.sort()
for i in z:
    print (i)

output: 1 2 3 4 5 6

Upvotes: 0

U13-Forward
U13-Forward

Reputation: 71570

Assuming python, use:

for x, y in zip(num1, num2):
    print x
    print y

Output:

1
2
3
4
5
6

Upvotes: 2

misaka_mikoto
misaka_mikoto

Reputation: 26

let num1=[1, 3, 5],num2 = [2, 4, 6]
let arr=num1.concat(num2).sort((a,b)=>a-b)
for(let i=0;i<arr.length;i++){
    console.log(arr[i])
}

Upvotes: 0

Related Questions