Convert List to String in Python
There are several ways to convert a list to a string in Python. Here are some of the most common methods:Using String join() Method
You can use the join method of strings to concatenate all the elements of a list into a single string, with a specified delimiter. The delimiter is a string that separates each element of the list in the final string.
list = ['East', 'West', 'North', 'South']
string = ' '.join(list)
print(string)
//Output: East West North South
Using String format() Method
You can use the str.format method to concatenate all the elements of a list into a string, with a specified delimiter. The delimiter can be a string or a special character.
list = ['East', 'West', 'North', 'South']
string = ' '.join(str(x) for x in list)
print(string)
//Output: East West North South
Using String Concatenation
You can concatenate all the elements of a list into a single string using a loop and the addition operator.
list = ['East', 'West', 'North', 'South']
string = ''
for element in list:
string += element + ' '
print(string)
//Output: East West North South
Using List Comprehension
In Python, you can convert a list to a string using a list comprehension and the join method of strings.
list = ['East', 'West', 'North', 'South']
string = ' '.join([str(element) for element in list])
print(string)
//Output: East West North South
In the above example, the list comprehension [str(element) for element in list] creates a new list of strings from the original list of elements. The join method then concatenates the elements of the new list into a single string, with a space as the delimiter.
Using enumerate function
In Python, you can convert a list to a string using the enumerate function and string concatenation.
list = ['East', 'West', 'North', 'South']
string = ''
for i, element in enumerate(list):
if i == len(list) - 1:
string += element
else:
string += element + ' '
print(string)
//Output: East West North South
In the above example, the enumerate function is used to loop over the elements of the list, along with their index i. The loop checks whether the current index is equal to the length of the list minus one, and if so, it concatenates the current element to the string without a delimiter. Otherwise, it concatenates the current element to the string with a space as the delimiter.
Using repr() Method

You can use the repr method to convert a list to a string, but this method returns a string representation of the list, including square brackets and commas, which may not be suitable for all use cases.
list = ['East', 'West', 'North', 'South']
string = repr(list)
print(string)
//Output: ['East', 'West', 'North', 'South']
Using json.dump() Method
If you want to convert a list to a string in JSON format, you can use the json.dumps method from the json module.
import json
list = ['East', 'West', 'North', 'South']
string = json.dumps(list)
print(string)
//Output:["East", "West", "North", "South"]
Choose the method that best fits your requirements based on the desired output format and any specific delimiter or separator you want to use.
Using functools.reduce method
You can convert a list to a string using the functools.reduce method and the join method of strings.
import functools
list = ['East', 'West', 'North', 'South']
string = functools.reduce(lambda x, y: x + ' ' + y, list)
print(string)
//Output: East West North South
In the above example, the functools.reduce method is used to apply a lambda function to the elements of the list, starting from the first two elements, and accumulating the results. The lambda function lambda x, y: x + ' ' + y concatenates two strings x and y with a space as the delimiter.
Note that the reduce method is available in the functools module in Python 3, but was moved to the functools module in Python 2. In Python 2, you can import the reduce method directly from the functools module without importing the entire module.
Related Topics
- Print the following pattern using python
- Python Program to Check Leap Year
- Remove first n characters from a string | Python
- Check if the first and last number of a list is the same | Python
- Number of occurrences of a substring in a string in Python
- Remove last element from list in Python
- How to Use Modulo Operator in Python
- Enumerate() in Python
- Writing to a File using Python's print() Function
- How to read csv file in Python
- Dictionary Comprehension in Python
- How to convert int to string in Python
- Random Float numbers in Python