Robotics & Artificial Intelligence
Write a Python program that performs the following tasks on a tuple.
- Create a tuple with elements (12, 27, 30, 47, 55, 49)
- Convert tuple into list.
- Remove element 30 from the list.
- Append a new list with elements [5, 25]
- Insert element 11 at index 3.
- Print the list.
- Convert the list to a tuple.
Answer
tup = (12, 27, 30, 47, 55, 49)
lst = list(tup)
lst.remove(30)
lst.append([5, 25])
lst.insert(3, 11)
print("List after operations:")
print(lst)
tup2 = tuple(lst)
print("Converted tuple:")
print(tup2)Output
List after operations:
[12, 27, 47, 11, 55, 49, [5, 25]]
Converted tuple:
(12, 27, 47, 11, 55, 49, [5, 25])