1

How do I convert

[('Paulo Coelho', 74, 'brasileño'), ('Ziraldo', 89, 'brasileño')]

to

[['Paulo Coelho', 74, 'brasileño'], ['Ziraldo', 89, 'brasileño']]

any method for different sizes of tuples?

  • 3
    Does this answer your question? [Convert a list of tuples to a list of lists](https://stackoverflow.com/questions/14831830/convert-a-list-of-tuples-to-a-list-of-lists) – Nick is tired Nov 14 '21 at 03:53

3 Answers3

5

You can use list() and list comprehension.

>>> l = [('Paulo Coelho', 74, 'brasileño'), ('Ziraldo', 89, 'brasileño')]
>>> c = [list(t) for t in l]
>>> c
[['Paulo Coelho', 74, 'brasileño'], ['Ziraldo', 89, 'brasileño']]
Timus
  • 10,974
  • 5
  • 14
  • 28
vanngao09
  • 94
  • 4
2

All you need to do is loop through the list and convert every element from a tuple to a list using list()

for i in range(len(lis)):
    lis[i] = list(lis[i])
Ayub Farah
  • 31
  • 2
1

list() function will convert tuple into list. To convert all tuples in array you have to traverse.

arr = [('Paulo Coelho', 74, 'brasileño'), ('Ziraldo', 89, 'brasileño')]
for i in range(len(arr)):
    arr[i] = list(arr[i])
Timus
  • 10,974
  • 5
  • 14
  • 28