+ 2
Tuples and Lists
How can I take tuples and make list?
10 Respuestas
+ 1
def my_func(*my_tuple):
return list(my_tuple)
print (my_func (input()))
Elena Vitsiou
+ 3
Can u explain more what u need ?
U need to take tuple from user or anything other?
And u want to make the tuple list or what u need ?
+ 2
XXX thank you!
+ 1
Dolphin I want to take a tuple from a user and make it a list to change it.
+ 1
Elena Vitsiou
You can convert tuple to list by passing it to the list constructor
```
tup = (1, 2, 3)
list_tup = list(tup)
# list_tup is [1, 2, 3]
```
+ 1
Elena Vitsiou
XXX
Another Solution without using built-in function like list() function
def my_func(*my_tuple):
my_list = []
for num in my_tuple :
my_list.append(num)
return my_list
print (my_func (input()))
+ 1
Elena Vitsiou
List comprehension along with zip() function is used to convert the tuples to list and create a list of tuples. Python iter() function is used to iterate an element of an object at a time. The 'number' would specify the number of elements to be clubbed into a single tuple to form a list.
https://www.askpython.com/python/list/python-list-of-tuples#:~:text=List%20comprehension%20along%20with%20zip,tuple%20to%20form%20a%20list.
+ 1
Actually a tuple is a list but the elements are fixed....if you want insertion or deletion use a list and declare it as such.
0
Dolphin
The output of your code will always be a list with 1 string. The OP only asked how to convert a tuple to list, just answer that. Why overcomplicate your answer and still give a solution which is of little use?