String Split and Join - HackerRank Python String Problem Solution

String Split and Join - HackerRank Python String Problem Solution

Instructor-svgAl-Mamun Sarkar
Mar 23 , 2020

String Split and Join - HackerRank Python String Problem Solution. Split the given string on a " " (space) delimiter and join the string using a - hyphen.  Click here to see the problem. 

Code:


def split_and_join(line):
    str_arr = line.split(" ")
    return "-".join(str_arr)


if __name__ == '__main__':
    line = input()
    result = split_and_join(line)
    print(result)

Sample Input

Hello Word

Sample Output

Hello-World
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram