Write the Python Program for the following :
• Take 3 names as input from the user. Store these names in a list. Shift all the 3 names to a single variable and delete the list
pls answer this
Answers
Transversal list( )
# Python3 program to remove the index
# element from the list
# using traversal
def remove(list1, pos):
newlist = []
# traverse in the list
for x in range(len(list1)):
# if index not equal to pos
if x != pos:
newlist.append(list1[x])
print(*newlist)
# driver code
list1 = [10, 20, 30, 40, 50]
pos = 2
remove(list1, pos)
Method 2 pop( )
# Python3 program to remove the index
# element from the list
# using pop()
def remove(list1, pos):
# pop the element at index = pos
list1.pop(pos)
print(*list1)
# driver code
list1 = [10, 20, 30, 40, 50]
pos = 2
remove(list1, pos)
Del function ( )
# Python3 program to remove the index element
# from the list using del
def remove(list1, pos):
# delete the element at index = pos
del list1[pos]
print(*list1)
# driver code
list1 = [10, 20, 30, 40, 50]
pos = 2
remove(list1, pos)
I think this much is enough
Based on c++ program
Follow for further help