In this HackerRank string split and join problem solution in python we need to read a string and separate all its words by space and then we need to add all these words with a hyphen ( - ) and then we need to print that string on the output screen.

HackerRank String split and join solution in python

Problem solution in Python 2 programming.

print '-'.join(raw_input().split())

Problem solution in Python 3 programming.

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

Problem solution in pypy programming.

def split_and_join(line):
    return line.replace(' ', '-')

Problem solution in pypy3 programming.

print ("-".join(input().split()))