Robotics & Artificial Intelligence

Write a Python program that performs the following tasks on a tuple.

  1. Create a tuple with elements (12, 27, 30, 47, 55, 49)
  2. Convert tuple into list.
  3. Remove element 30 from the list.
  4. Append a new list with elements [5, 25]
  5. Insert element 11 at index 3.
  6. Print the list.
  7. Convert the list to a tuple.

Python Tuples

3 Likes

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])

Answered By

2 Likes


Related Questions