Python - Convert list of strings and characters to list of characters
Last Updated :
11 Jul, 2025
Sometimes we come forward to the problem in which we receive a list that consists of strings and characters mixed and the task we need to perform is converting that mixed list to a list consisting entirely of characters.
itertools.chain() combines multiple lists or iterables into one, without creating extra copies of the data. It’s fast and memory-efficient because it processes the items one by one, directly from the source.
Python
import itertools
# Flatten the list of strings into individual characters
li = ['gfg', 'i', 's', 'be', 's', 't']
# Unpacks and combines the strings into one iterable
res = list(itertools.chain(*li))
print(res)
Output['g', 'f', 'g', 'i', 's', 'b', 'e', 's', 't']
Explanation:
*li
: This unpacks the list so each string is passed as a separate argument to chain
.itertools.chain(*li)
: This combines all characters from the strings into one iterable.list()
: This converts the iterable into a list of characters.
Using List comprehension
List comprehension lets us quickly create a new list by looping through an existing list. It's a simple way to flatten nested lists or transform data, all in one line, making our code cleaner and easier to read.
Python
li= ['gfg', 'i', 's', 'be', 's', 't']
res = [i for ele in li for i in ele]
print(res)
Output['g', 'f', 'g', 'i', 's', 'b', 'e', 's', 't']
Explanation:
for ele in li
: This loops through each string in the list li
.for i in ele
: This loops through each character in the current string ele
.[i for ele in li for i in ele]
:This
combines both loops into one, creating a list of all characters from all strings in li
.
Using join()
join()
method combines all the strings in a list into one long string. After that, we turn this single string into a list of individual characters. It’s a bit less efficient than the other methods because it first combines everything into one string before breaking it down into characters.
Python
li = ['gfg', 'i', 's', 'be', 's', 't']
res = list(''.join(li))
print(res)
Output['g', 'f', 'g', 'i', 's', 'b', 'e', 's', 't']
Explanation:
- ''.join(li): This combines all the strings in the list into one long string without any spaces, resulting in 'gfgisbest'.
- list(''.join(li)): This converts that long string into a list of individual characters .
Using map()
map() turn each string into a list of characters, and then itertools.chain() merges them into one continuous sequence. It's effective but less efficient than chain.from_iterable() because it creates extra intermediate lists, using more memory.
Python
from itertools import chain
li = ['gfg', 'i', 's', 'be', 's', 't']
res = list(chain(*map(list, li)))
print(res)
Output['g', 'f', 'g', 'i', 's', 'b', 'e', 's', 't']
Explanation:
map(list, li)
: This converts each string to a list of characters.chain(*...)
: This flattens the lists into a single iterable.list()
: This converts the iterable into a list.
Using for loop ()
nested for loop method is slow for large datasets because it has to go through each character in every string in the list, resulting in many extra iterations. This makes it the least efficient approach, especially when dealing with big lists.
Python
li = ['gfg', 'i', 's', 'be', 's', 't']
# Create an empty list to store result
res = []
for ele in li:
for i in ele:
res.append(i)
print(res)
Output['g', 'f', 'g', 'i', 's', 'b', 'e', 's', 't']
Explanation:
for ele in li
: This loops through each string in the list.for i in ele
: This loops through each character in the current string ele
.res.append(i)
: This appends each character i
to the res
list.
Similar Reads
Python | Convert string List to Nested Character List Sometimes, while working with Python, we can have a problem in which we need to perform interconversion of data. In this article we discuss converting String list to Nested Character list split by comma. Let's discuss certain ways in which this task can be performed. Method #1 : Using list comprehen
7 min read
Python - Convert List of Integers to a List of Strings We are given a list of integers and our task is to convert each integer into its string representation. For example, if we have a list like [1, 2, 3] then the output should be ['1', '2', '3']. In Python, there are multiple ways to do this efficiently, some of them are: using functions like map(), re
3 min read
Python | Convert List of lists to list of Strings Interconversion of data is very popular nowadays and has many applications. In this scenario, we can have a problem in which we need to convert a list of lists, i.e matrix into list of strings. Let's discuss certain ways in which this task can be performed. Method #1 : Using list comprehension + joi
4 min read
Python - Convert case of elements in a list of strings In Python, we often need to convert the case of elements in a list of strings for various reasons such as standardizing input or formatting text. Whether it's converting all characters to uppercase, lowercase, or even swapping cases. In this article, we'll explore several methods to convert the case
3 min read
Convert List of Tuples to List of Strings - Python The task is to convert a list of tuples where each tuple contains individual characters, into a list of strings by concatenating the characters in each tuple. This involves taking each tuple, joining its elements into a single string, and creating a new list containing these strings.For example, giv
3 min read
Python - Convert Strings to Character Matrix Sometimes, while dealing with String lists, we can have a problem in which we need to convert the Strings in list to separate character list. Overall converting into Matrix. This can have multiple applications in data science domain in which we deal with lots of data. Lets discuss certain ways in wh
3 min read