In [1]:
# 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 = [5, 10, 15, 20, 25, 50, 20]
index = list1.index(20)
list1[index] = 200
print(list1)
[5, 10, 15, 200, 25, 50, 20]
In [2]:
# Write a program to remove all occurrences of item 20.

list1 = [5, 20, 15, 20, 25, 50, 20]

def remove_value(sample_list, val):
    return [i for i in sample_list if i != val]

res = remove_value(list1, 20)
print(res)
[5, 15, 25, 50]
In [3]:
# Write a program to iterate both lists simultaneously and display items from list1 in original order and items from list2 in reverse order.

list1 = [10, 20, 30, 40]
list2 = [100, 200, 300, 400]

for x, y in zip(list1, list2[::-1]):
    print(x, y)
10 400
20 300
30 200
40 100
In [27]:
!jupyter nbconvert  Assignment_4 (3).ipynb
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `jupyter nbconvert  Assignment_4 (3).ipynb'