Change language

# Python | Convert a list of tuples to a list of strings

|

Method # 1: Using list comprehension + `join()`
List comprehension performs the task of iterating through the entire list of tuples, and the join function performs the task of joining the elements of a tuple into one list.

 ` # Python3 demo code ` ` # convert a tuple list to a list of list ` ` # using a list comprehension + join () `   ` # initializing list ` ` test_list ` ` = ` ` [(` ` ’G’ ` `, ` `’ E’ ` `, ` ` ’E’ ` `, ` ` ’K’ ` `, ` ` ’S’ ` `), (` `’ F’ ` `, ` ` ’O’ ` `, ` ` ’R’ ` `), ` ` ` ` (` ` ’G’ ` `, ` `’ E’ ` `, ` ` ’E’ ` `, ` ` ’K’ ` `, ` `’ S’ ` `)] `   ` # print original list ` ` print ` ` (` ` "The original list is:" ` ` + ` ` str ` ` (test_list)) ` ` `  ` # using a list comprehension + join () ` ` # converting a list tuple to the list of list ` ` res ` ` = ` ` [’ ’.join (i) ` ` for ` ` i ` ` in ` ` test_list] `   ` # print result ` ` print ` ` (` ` "The list after conversion to list of string: "` ` + ` ` str ` ` (res)) `

Output:

The original list is: [(’G’, ’E’, ’E’, ’K’, ’S’), (’F’, ’O’, ’R’), (’G’, ’E’, ’E’, ’K’, ’S’)]
The list after conversion to li st of string: [’GEEKS’, ’FOR’, ’GEEKS’]

Method # 2: Using ` map () + join () `
The task of comprehending a list can be accomplished by the map function, which can expand the logic of one tuple to all tuples in the list.

 ` # Python3 demo code ` ` # convert a list of a tuple to a list of a list ` ` # using map ( ) + join () `   ` # initializing list ` ` test_list ` ` = ` ` [(` `’ G’ ` `, ` ` ’E’ ` `, ` ` ’E’ ` `, ` `’ K’ ` `, ` ` ’S’ ` `), (` ` ’F’ ` `, ` `’ O’ ` `, ` ` ’R’ ` `), ` ` (` ` ’G’ ` `, ` ` ’E’ ` `, ` `’ E ’` `, ` `’ K’ ` `, ` ` ’S’ ` `)] ` ` `  ` # print original list ` ` print ` ` (` ` "The original list is:" ` ` + ` ` str ` (test_list))   ` # using map () + join () ` ` # convert a tuple list to a list of list ` ` res ` ` = ` ` list ` ` (` ` map ` ` (’’ .join, test_list)) `   ` # print result ` ` print ` ` (` ` "The list after conversion to list of string:" ` ` + ` ` str ` ` (res)) `

Output:

The original list is: [(’G’, ’E’, ’E’, ’K’, ’S’), (’F’, ’ O ’,’ R ’), (’ G ’,’ E ’,’ E ’,’ K ’,’ S ’)]
The list a fter conversion to list of string: [’GEEKS’, ’FOR’, ’GEEKS’]

## Shop

Learn programming in R: courses

\$

Best Python online courses for 2022

\$

Best laptop for Fortnite

\$

Best laptop for Excel

\$

Best laptop for Solidworks

\$

Best laptop for Roblox

\$

Best computer for crypto mining

\$

Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

NUMPYNUMPY

glob exclude pattern

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

NUMPYNUMPY

Python CSV error: line contains NULL byte

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries