String Split and Join - HackerRank Python String Problem Solution

Author: Al-mamun Sarkar Date: 2020-03-23 19:35:45

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