
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to convert tuple into list by adding the given string after every element
When it is required to convert tuple into list by adding the given string after every element, the list comprehension is used.
Example
Below is a demonstration of the same −
my_tuple = ((15, 16), (71), 42, 99) print("The tuple is :") print(my_tuple) K = "Pyt" print("The value of K is :") print(K) my_result = [element for sub in my_tuple for element in (sub, K)] print("The result is :") print(my_result)
Output
The tuple is : ((15, 16), 71, 42, 99) The value of K is : Pyt The result is : [(15, 16), 'Pyt', 71, 'Pyt', 42, 'Pyt', 99, 'Pyt']
Explanation
A tuple of tuple of integers is defined and is displayed on the console.
A value for K is defined and is displayed on the console.
A list comprehension is used to iterate over the elements and the ‘in’ operator is used to check if element is same as the K value specified.
If yes, this is converted to a list, and is assigned to a variable
This is the output that is displayed on the console.
- Related Articles
- Python program to covert tuple into list by adding the given string after every element
- Python program to convert Set into Tuple and Tuple into Set
- Python – Extract Kth element of every Nth tuple in List
- How to convert a list into a tuple in Python?
- Python - Convert given list into nested list
- Convert a list into tuple of lists in Python
- Python Program to Convert List into Array
- Python Program To Convert An Array List Into A String And Viceversa
- Convert given array to Arithmetic Progression by adding an element in C++
- Python – Append given number with every element of the list
- Adding Tuple to List and vice versa in Python
- Convert String to Tuple in Python
- Python program to convert a list to string
- Python program to convert a string into uppercase
- Python program to convert a string into lowercase

Advertisements