#1. 1. 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.
list1=[]
n= int(input("Enter number of elements in the list:"))
for i in range(0,n):
lst=input()
list1.append(lst)
print("first list:",list1)
if '20' in list1:
index1=list1.index('20')
list1[index1]='200'
else:
print("Element 20 is not available in the list" )
print("updated list:",list1)
Enter number of elements in the list:4 23 34 20 20 first list: ['23', '34', '20', '20'] updated list: ['23', '34', '200', '20']
#2. Given a Python list, write a program to remove all occurrences of item 20.
list1=[]
n= int(input("Enter number of elements in the list:"))
for i in range(0,n):
lst=input()
list1.append(lst)
print("first list:",list1)
for i in range(0,list1.count('20')):
list1.remove('20')
print("updated list:",list1)
Enter number of elements in the list:4 23 20 34 20 first list: ['23', '20', '34', '20'] updated list: ['23', '34']
#3. 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]
list1=[10,20,30,40]
list2=[100,200,300,400]
list2.reverse()
for i,j in zip(list1,list2):
print(i," ",j)
print(" ")
10 400 20 300 30 200 40 100