String Split and Join
Objective:
In Python, a string can be split on a delimiter.
Example:
>>> a = "this is a string"
>>> a = a.split(" ") # a is converted to a list of strings.
>>> print a
['this', 'is', 'a', 'string']
Joining a string is simple:
>>> a = "-".join(a)
>>> print a
this-is-a-string
Task
You are given a string. Split the string on a " " (space) delimiter and join using a - hyphen.
Solution:
def split_and_join(line): result = "-".join(line.split(" ")) return result if __name__ == '__main__': line = input() result = split_and_join(line) print(result) |
Note:
This Code is Verified by all Test Cases.If any error occurs then Comment correct code Below in comment box.
Disclaimer:-
The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.
String Split and Join - Hackerrank Solution
Reviewed by CodexRitik
on
March 24, 2020
Rating:
![String Split and Join - Hackerrank Solution](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT-c2YJMTy15gzM_68mgjlWh8aRvW1TfvMU2hZ_RVoVJ2j3U3ve3GINiJGULOraG4GMzWbuYx720zKYrIPVk5TH8g6V9aVtjkxFEKjp3cj-DlDBF-bWIKZpjJS4sT7DPTmCINm1E02Ofc/s72-w200-c-h146/PicsArt_12-05-08.28.13%255B1%255D.jpg)
Thanks Man For Positive feedback.
ReplyDelete