merging two lists in python

Description

Python Program to get two lists and merge them into single list.

Input:
3
5 4 2
4
9 7 6 3
Output:
5 4 2 9 7 6 3

Solution

l1=list(map(int,input("Enter Numbers:").split()))
l2=list(map(int,input("Enter Numbers:").split()))
l3=[None]* (len(l1)+len(l2))
k=0
for i in range(0,len(l1)):
    l3[k]=l1[i]
    k+=1

for i in range(0,len(l2)):
    l3[k]=l2[i]
    k+=1

print(l3)

Explanation

Create a new list with size of size of a list  + size of b list.
l3  = len(l1) + len(l2)
 
visit elements of list l1 and store it in l3.
l3[k]=l1[i]

visit elements of list l2 and store it in l3.
l3[k]=l2[i]









Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution