
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to split a string and join with comma
Suppose we have few words that are separated by spaces. We have to split these words to form a list, then join them into a string by placing comma in-between.
So, if the input is like s = "Programming Python Language Easy Funny", then the output will be Programming, Python, Language, Easy, Funny
To solve this, we will follow these steps −
words := a list of words by applying split function on s with delimiter " " blank space.
ret := join each items present in words and place ", " in between each pair of words
return ret
Example
Let us see the following implementation to get better understanding
def solve(s): words = s.split(' ') ret = ', '.join(words) return ret s = "Programming Python Language Easy Funny" print(solve(s))
Input
"Programming Python Language Easy Funny"
Output
Programming, Python, Language, Easy, Funny
- Related Questions & Answers
- Python program to split and join a string?
- C# program to split and join a string
- Java program to split and join a string
- Split String with Comma (,) in Java
- Java Program to split a string with dot
- PHP program to split a given comma delimited string into an array of values
- How to split comma and semicolon separated string into a two-dimensional array in JavaScript ?
- How to split a string in Python
- Python program to split string into k distinct partitions
- Java Program to Convert a List of String to Comma Separated String
- C# Program to split a string on spaces
- Program to find number of ways to split a string in Python
- How to Split a String with Escaped Delimiters?
- How to split a string with a string delimiter in C#?
- Java regex program to split a string with line endings as delimiter
Advertisements