Assignment#4 : Mohammed Abdul Wasay
Given input : list1 = [5, 10, 15, 20, 25, 50, 20]
Expected output: [5, 10, 15, 200, 25, 50, 20]
# Printing value of 4th index item in a given list
list1 = [5, 10, 15, 20, 25, 50, 20]
print(list1[3])
20
# updating an item in a list (index = 3) with a value of 200
list1[3]=200
print(list1)
[5, 10, 15, 200, 25, 50, 20]
Given input : list1 = [5, 20, 15, 20, 25, 50, 20]
Expected output:[5, 15, 25, 50]
list1 = [5, 10, 15, 20, 25, 50, 20]
print(list1)
[5, 10, 15, 20, 25, 50, 20]
list1 = [5, 20, 15, 20, 25, 50, 20]
def check(list1, val):
n=0
# traverse in the list
for x in list1:
# compare with all the values
# with val
if val == list1[n]:
list1.pop(n)
n=n+1
check(list1,20)
print(list1)
[5, 15, 25, 50]
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]
print(list1)
print(list2)
[10, 20, 30, 40] [100, 200, 300, 400]
list1.sort()
print(list1)
list2.sort(reverse=True)
print(list2)
[10, 20, 30, 40] [400, 300, 200, 100]