We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Strings
- String Split and Join
- Discussions
String Split and Join
String Split and Join
Sort by
recency
|
1094 Discussions
|
Please Login in order to post a comment
A Better Approach
def split_and_join(line): # write your code here return line.replace(" ", "-")
if name == 'main': line = input() result = split_and_join(line) print(result)
Absolutely! In Python, using method is a simple and powerful way to break a string into a list based on a specified delimiter. My fairplay
My brute force solution: Time Complexity : O(n^2) Space Complexity : O(n)
Better optimization solutions
Time Complexity: O(n) Space Complexity: O(n)
def split_and_join(line):
a=input() print("-".join(a.split())) if name == 'main': line = input() result = split_and_join(line) print(result)
s=input(); s=s.replace(' ','-'); print(s)