You need if to skip separator before first char

def to_string(my_list, sep=', '):

    string = ''

    for char in my_list:
        if string: # if string is not empty then add separator
            string = string + sep
        string = string + char

    return string

my_list = ['H','E','L','p']
print(to_string(my_list, '-'))

Other method is to get first char and always add separator. But it needs to check if list is not empty.

def to_string(my_list, sep=', '):

    if not my_list:
        return ''

    string = my_list[0]

    for char in my_list[1:]:
        string = string + sep + char

    return string

my_list = ['H','E','L','p']
print(to_string(my_list, '-'))
Answer from furas on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-convert-a-list-to-string
Python Program to Convert a List to String - GeeksforGeeks
May 8, 2026 - Another approach is to use a loop (for loop) to iterate through the list and concatenate each element to a result string. This method provides more control if we need to manipulate each element before adding it to the string.
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ how to convert list to string in python
How to convert List to String in Python
November 7, 2024 - Here the datatype was different as the elements were not strings, and therefore, we needed to convert them into the list first using the str() function with an iterable over all elements of the list using for loop.
Discussions

Converting list to string
Use the join method on strings: ''.join(password) More on reddit.com
๐ŸŒ r/learnpython
14
8
December 22, 2024
python - How to convert list to string - Stack Overflow
How can I convert a list to a string using Python? More on stackoverflow.com
๐ŸŒ stackoverflow.com
convert list thats a string back to a list?
How did you read the CSV? How did that data get into the CSV in the first place? You could solve this by using ast.literal_eval() but it would certainly be better to fix it before it gets to that point. More on reddit.com
๐ŸŒ r/learnpython
24
3
March 11, 2024
Python AI game: convert list of lists and string to set
Because lists are mutable, they are not hashable. Similarly, because tuples are immutable, they are hashable. Just change every instance of a sublist into a tuple, eg.[((2, 4), 'E'), ((2, 4), 'SW'), (((2, 4), (2, 5)), 'SE')]. Also, as every element is a 2-tuple, it seems like you could also be using a dictionary instead of a set. More on reddit.com
๐ŸŒ r/learnpython
5
1
April 25, 2021
๐ŸŒ
4Geeks
4geeks.com โ€บ en โ€บ how-to โ€บ convert-list-to-string-in-python
Convert List to String in Python
July 16, 2025 - Our last "trick" to convert any list to string in Python is by just iterating through the elements of a list and concatenating the same in a new string variable, this is done by using a for loop.
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ python-list-manipulation-convert-lists-to-strings
Python List Manipulation: Convert Lists to Strings - StrataScratch
April 4, 2025 - Pythonโ€™s join() method canโ€™t handle None directly โ€“ it expects all items to be strings. If you pass a list with None, itโ€™ll throw a TypeError. The solution is to use a comprehension or map() to convert all items to strings.
๐ŸŒ
Kochiva
kochiva.com โ€บ home โ€บ how to convert a list to string in python?
How to Convert a List to String in Python easily 2025
March 26, 2026 - The join() function iterates through each element in the list and concatenates them together using the specified separator. Another simple way to convert a Python list to a string is using the str () function.
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ list โ€บ list-to-string
How to Convert List to String in Python - Multiple Methods - AskPython
May 27, 2023 - This is one of the most commonly used methods for this conversion as it only uses the for loop, no additional method is needed here. ... Even a set of characters in the form of a list can be converted to a string in the same manner as above. Below is an example to demonstrate the conversion of a list of characters to a string. ... inp_str = ['J', 'o', 'u', 'r', 'n', 'a', 'l', 'd', 'e', 'v'] st = "" for x in inp_str: st += x print(st) ... In this tutorial, we explored four different ways to convert a list to string in Python programming language.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ converting list to string
r/learnpython on Reddit: Converting list to string
December 22, 2024 -

Hi everyone, I just wanted to know what is the best way to convert an entire list to a simple string element. I was trying out stuff I learned by coding a (very) simple password generator and I am stuck at figuring out how to output the password as a single string (without the empty spaces and brackets) instead of getting the entire array.

My code :

import string
import random
letters = list(string.ascii_lowercase)

#Generates a random password with default value of 3 numbers and 3 letters (x and y arguments)
def password_gen(x=3, y=3):

  char_list = []

  #Returns a random letter
  def add_letter() :
  return random.choice(letters)

  #Returns a random number (0-9)
  def add_number() :
  return int(random.random()*10)

  #Loops to add the correct number of random characters
  i = 0
  while i < x :
    char_list.append(add_letter())
    i+=1
    i=0
  while i < y :
    char_list.append(add_number())
    i+=1
  
  #Shuffles the list and returns it as the generated password
  random.shuffle(char_list)
  return char_list

password = str(password_gen(5, 5))
print(password)

Currently the output gives something looking like this : ['p', 3, 5, 9, 'o', 'v', 'a', 9, 't', 3] and I want it to look like this p359ova9t3

Find elsewhere
๐ŸŒ
Devloprr
devloprr.com โ€บ other โ€บ convert-list-to-string-in-python
Convert List To String In Python
In this code example, we create a function to convert a list to a string. We create an empty string s. Then we can use for loop to iterate each element present in the list of strings.
๐ŸŒ
SPEC INDIA
spec-india.com โ€บ blog โ€บ python-list-to-string
Python List to String Conversion: Easy Methods & Examples
October 28, 2024 - The list is traversed using a for loop and one by one, every element is added to the string. Example: name_list = ['Cristiano_', 'Ronaldo_', 'dos_', 'Santos_', 'Aveiro'] full_name = "" #traversing the list for name in name_list: full_name += ...
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ list-to-string-python
Convert List to String in Python: 7 Best Methods (with code)
June 8, 2023 - And later uses a for loop to traverse the elements by element-wise patterns. After the traversal of elements by list comprehension, you can use the join() method to concatenate the traversed elements of the list into an empty string.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ how to convert a list to string in python easily [2026]
How to Convert a List to String in Python Easily [2026]
August 23, 2026 - Learn the fastest, cleanest ways to convert a Python list to a string using join(), map(), list comprehension, and more, with copy-paste code examples.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
Altcademy
altcademy.com โ€บ blog โ€บ how-to-convert-a-list-to-a-string-in-python
How to convert a list to a string in Python - Altcademy.com
June 13, 2023 - Using the map() function to convert a list to a string is like using a machine that processes each element of the list one by one and outputs a new list with the processed elements. In our case, the machine converts each number to its string representation. Finally, the join() method is like assembling the processed elements into a single string using a separator. You can also use a traditional for loop to convert a list to a string.
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ convert-list-to-string-python
Convert list to string in Python - 3 easy ways - Flexiple Tutorial - Flexiple
March 10, 2022 - The third method to convert lists to strings in python is to loop over each object and append it into a string.
๐ŸŒ
STechies
stechies.com โ€บ convert-list-string-python
How to Convert List to String in Python with Examples
In the above example, we used the map() function to convert the list into a string and, lastly, added the join() function to merge all the elements returned by the str() function. In Python, list comprehension creates a list of items from the existing list. It then uses the for loop to traverse the iterable elements in an element-wise format.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-each-item-in-the-list-to-string-using-python
Convert Each Item in the List to String using Python - GeeksforGeeks
July 23, 2025 - A list comprehension provides a compact way to loop through a list and apply a transformation to each item. In this case, we apply str() to each item in the list and create a new list with the string values.
๐ŸŒ
Medium
medium.com โ€บ simplilearn-engineering โ€บ how-to-convert-list-to-string-in-python-here-are-the-6-ways-to-know-simplilearn-f38d7f5b305
How to Convert List to String in Python? Here are the 6 Ways to Know | Simplilearn | by Simplilearn | Simplilearn Engineering | Medium
December 22, 2022 - To convert a list to a string, use Python List Comprehension and the join() function. The list comprehension will traverse the elements one by one, and the join() method will concatenate the listโ€™s elements into a new string and return it ...
๐ŸŒ
PythonForBeginners.com
pythonforbeginners.com โ€บ home โ€บ convert a list to string in python
Convert a List to String in Python - PythonForBeginners.com
July 29, 2021 - The easiest way to convert a list to a string in python is by using for loop and string concatenation. To convert a list to a string, we can simply convert each element of the list to a string.
๐ŸŒ
FITA Academy
fita.in โ€บ how-to-convert-list-to-string-in-python
How To Convert List To String In Python? | Python String | FITA Academy
Prashanth - This was all about converting lists to string and strings to lists..To get in-depth knowledge of Python along with its various applications and real-time projects. I joined in FITA to pursue Expertise in Digital Marketing. The training they had given to me is wonderful and they taught more tools and working knowledge in digital marketing. Efficient trainer. He gave me many tips and tricks on how to handle and survive in the field of digital marketing. Overall its a best place to learn Digital marketing course. FITA is a leading Training and Placement company managed by IT veterans with more th
Rating: 5 โ€‹
Address: Plot No 7, 2nd floor, Vadivelan Nagar, Velachery Main Road, Velachery, 600042, Chennai