1# Python program to convert a list
2# to string using list comprehension
3
4s = ['I', 'want', 4, 'apples', 'and', 18, 'bananas']
5
6# using list comprehension
7listToStr = ' '.join([str(elem) for elem in s])
8
9print(listToStr)
1list_of_num = [1, 2, 3, 4, 5]
2# Covert list of integers to a string
3full_str = ' '.join([str(elem) for elem in list_of_num])
4print(full_str)
1# Python list to string
2
3some_list = ['Bob', 'has', 'four', 'dogs'] # the base list
4
5list_to_string = ' '.join(some_list) # using the join() we can join the list into a string
6# the ' ' in the start is the way we want to connect the list
7# if we will do '/' the string will look like Bob/has/four/dogs
8
9print(list_ro_string) # Prints the string
10
11===============================================================
12# Output:
13
14>>> 'Bob has four dogs'
1mystring = 'hello, world'
2
3mylist = string1.split(', ') #output => ['hello', 'world']
4
5myjoin1 = ', '.join(mylist) #output => 'hello, world'
6myjoin2 = ' '.join(mylist) #output => 'hello world'
7myjoin3 = ','.join(mylist) #output => 'hello,world'