- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to covert tuple into list by adding the given string after every element
When it is required to convert a tuple into a list, by the addition of a string after every element, list comprehension is used.
Below is a demonstration of the same −
my_tup = (56, 78, 91, 32, 45, 11, 23) print("The tuple is : ") print(my_tup) K = "Hi" my_result = [elem for sub in my_tup for elem in (sub, K)] print("The tuple after conversion with K is : ") print(my_result)
The tuple is : (56, 78, 91, 32, 45, 11, 23) The tuple after conversion with K is : [56, 'Hi', 78, 'Hi', 91, 'Hi', 32, 'Hi', 45, 'Hi', 11, 'Hi', 23, 'Hi']
A tuple is defined, and is displayed on the console.
The value of K, a string, is defined.
The list comprehension is used to iterate through the tuple elements, and convert it into a list.
This is assigned to a variable.
This is displayed as output on the console.
- Python program to convert tuple into list by adding the given string after every element
- Python – Extract Kth element of every Nth tuple in List
- Python – Append given number with every element of the list
- Python Categorize the given list by string size
- Adding Tuple to List and vice versa in Python
- Python program to convert Set into Tuple and Tuple into Set
- Program to insert new element into a linked list before the given position in Python
- Python program to sort a tuple by its float element
- Python program to insert an element into sorted list
- Python Program to remove a specific digit from every element of the list
- Program to find island count by adding blocks into grid one by one in Python
- Python program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple
- Adding an element to the List in C#
- Python program to compute the power by Index element in List
- Adding an element into the Hashtable in C#