You have given a Python list. Write a program to find value 20 in the list, and if it is present, replace it with 200. Only update the first occurrence of an item.
Given input : list1 = [5, 10, 15, 20, 25, 50, 20]
Expected output: [5, 10, 15, 200, 25, 50, 20]
list1 = [5,10,15,20,25,50,20]
index_20 = list1.index(20)
list1[index_20] = 200
print(list1)
[5, 10, 15, 200, 25, 50, 20]
Given a Python list, write a program to remove all occurrences of item 20.
Given input : list1 = [5, 20, 15, 20, 25, 50, 20]
Expected output:[5, 15, 25, 50]
list1 = [5,20,15,20,25,50,20]
for n in range(len(list1)):
if 20 in list1:
list1.remove(20)
print(list1)
[5, 15, 25, 50]
Given a two Python list. Write a program to iterate both lists simultaneously and display items from list1 in original order and items from list2 in reverse order.
Given input :
list1 = [10, 20, 30, 40]
list2 = [100, 200, 300, 400]
Expected output: 10 400 20 300 30 200 40 100
list1 = [10,20,30,40]
list2 = [100,200,300,400]
list3 = []
list3 = list2[::-1]
for (m,n) in zip(list1,list3):
print(m,n)
10 400 20 300 30 200 40 100