5(iii)
Write a Python program that performs the following tasks:
- (a)Create a tuple having elements (100, 200, 700, 300, 150)
- (b)Convert the above tuple to list.
- (c)Remove the element 700 and in its place insert an element 650.
- (d)Sort all the elements in ascending order.
- (e)Convert the list to a tuple.
- (f)Print the final tuple.
Show SolutionHide Solution↓
tup = (100, 200, 700, 300, 150)
lst = list(tup)
idx = lst.index(700)
lst.remove(700)
lst.insert(idx, 650)
lst.sort()
final_tup = tuple(lst)
print("Final tuple:")
print(final_tup)
Final tuple:
(100, 150, 200, 300, 650)