Menu Close

Insert and Extend in list

Write a program to append two list and calculate the length of the list. Kindly refer sample input and output for the task

Input:

  1. The Size of First List
  2. The Size of Second List
  3. First List elements
  4. Second List elements
  5. First List Element to be searched
  6. Second List Element to be searched
  7. Index number of the list to be added
  8. Element to be added in the list (Step 7)

Output:

  1. Extended List or appended list
  2. The index of the first list element (entered by user, Step 5)
  3. The index of the second list element (entered by user, Step 6)
  4. The updated list after inserting the element (entered by user in step 7 and 8)

Refer sample input and output for formatting specification.

N1=int(input("Enter the size of first list: "))
N2=int(input("Enter the size of second list: "))
l1=[]
l2=[]
print('Enter the first list elements: ')
for i in range(N1):
  l1.append(int(input('')))
print('Enter the second list elements: ')
for i in range(N2):
  l2.append(int(input('')))
s1=int(input('First List Element to be searched: '))
s2=int(input('Second List Element to be searched: '))
ind=int(input('Index number of the list to be added: '))
ele=int(input('Element to be added in the list:'))

l3=l1+l2
print('The Extended List')
print(l3)
print('Index for {} = {}'.format(s1,l3.index(s1)))
print('Index for {} = {}'.format(s2,l3.index(s2)))
print('After Inserting')
l3.insert(ind,ele)
print(l3)

Input_1:
Enter the size of first list: 2
Enter the size of second list: 2
Enter the first list elements:
25
23
Enter the second list elements:
9
20
First List Element to be searched: 25
Second List Element to be searched: 20
Index number of the list to be added: 1
Element to be added in the list:2509

Output:
The Extended List
[25, 23, 9, 20]
Index for 25 = 0
Index for 20 = 3
After Inserting
[25, 2509, 23, 9, 20]


Input_2:
Enter the size of first list: 3
Enter the size of second list: 3
Enter the first list elements:
81
71
61
Enter the second list elements:
10
20
30
First List Element to be searched: 81
Second List Element to be searched: 30
Index number of the list to be added: 4
Element to be added in the list:252025

Output:
The Extended List
[81, 71, 61, 10, 20, 30]
Index for 81 = 0
Index for 30 = 5
After Inserting
[81, 71, 61, 10, 252025, 20, 30]


Exec. on linux

Morae!Q!