Related Articles

Related Articles

Python | Convert list of strings to space separated string
  • Last Updated : 16 May, 2020

Given a list of strings, write a Python program to convert the given list of strings into a space-separated string.

Examples:

Input : ['geeks', 'for', 'geeks']
Output : geeks for geeks

Input : ['Python', 'Language']
Output : Python Language

Approach #1 : Python string translate()

The string translate() method returns a string where each character is mapped to its corresponding character in the translation table. The limitation of this method is that it does not work for Python 3 and above versions.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to Convert a list of 
# strings to space-separated string
  
def convert(lst):
      
    return str(lst).translate(None, '[],\'')
      
# Driver code
lst = ['geeks', 'for', 'geeks']
print(convert(lst))

chevron_right


Output:



geeks for geeks

 
Approach #2 : join() function
The join() method is a string method and returns a string in which the elements of sequence have been joined by str separator. In this approach space is the separator.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to Convert list of 
# strings to space separated string
  
def convert(lst):
      
    return ' '.join(lst)
      
# Driver code
lst = ['geeks', 'for', 'geeks']
print(convert(lst))

chevron_right


Output:

geeks for geeks

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :