tuple to list in python

To convert a tuple to a list in Python, you can use the list() built-in function. Here's an example:

main.py
my_tuple = (1, 2, 3)
my_list = list(my_tuple)
print(my_list)  # Output: [1, 2, 3]
82 chars
4 lines

In this code block, my_tuple is defined as a tuple containing three elements. Then, the list() function is used to create a new list from my_tuple, which is assigned to my_list. Finally, my_list is printed out to the console using the print() function.

Using the list() function is a quick and easy way to convert a tuple to a list.

related categories

gistlibby LogSnag