In this python tuple program, we will convert a tuple into a list by adding the string after every element of the tuple.
Steps to solve the program
- Take a tuple and a string as input.
- Create an empty list.
- Use a for loop to iterate over elements in the tuple.
- Add the element and the string to the empty list using append().
- Repeat the process for all elements.
- Print the output.
a = (1,2,3,4)
print("Tuple: ",a)
b= 'sqatools'
print("String: ",b)
l = []
for ele in a:
l.append(ele)
l.append(b)
Output :
Tuple: (1, 2, 3, 4)
String: sqatools
New list: [1, 'sqatools', 2, 'sqatools', 3, 'sqatools', 4, 'sqatools']
flatten a tuple list into a string.