Python 3 Script to Convert List to String Using .join() and .map() Methods Full Project For Beginners

You are currently viewing Python 3 Script to Convert List to String Using .join() and .map() Methods Full Project For Beginners

 

Welcome folks today in this blog post we will be converting list to string using .join() and .map() methods in python. All the full source code of the application is given below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

 

Now firstly we will be using the .join() method

 

 

# Python program to convert a list
# to string using join() function
    
# Function to convert
def listToString(s):
    
    # initialize an empty string
    str1 = " "
    
    # return string
    return (str1.join(s))
        
        
# Driver code   
s = ['Geeks', 'for', 'Geeks']
print(listToString(s))

 

 

Now we will be using the .map() method

 

 

app.py

 

 

# Python program to convert a list
# to string using list comprehension
   
s = ['I', 'want', 4, 'apples', 'and', 18, 'bananas']
  
# using list comprehension
listToStr = ' '.join(map(str, s))
  
print(listToStr)

 

 

 

Now if we execute the app.py file we will be seeing the below screenshot

 

 

Leave a Reply