String Split and Join

Sort by

recency

|

1076 Discussions

|

  • + 0 comments

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

    return j_line 
    
  • + 0 comments

    we can use this two methods adn make the code short and easy

    words = line.split()
    return '-'.join(words)
    
        or
    
    return line.replace(" ", "-")
    
  • + 0 comments

    def split_and_join(line): # write your code here a=line.split() a='-'.join(a) return a if name == 'main': line = input() result = split_and_join(line) print(result)

  • [deleted]
    + 0 comments

    For Python3

    def split_and_join(line):
        return "-".join(line.split())
    
    if __name__ == '__main__':
        line = input()
        result = split_and_join(line)
        print(result)
    
  • + 0 comments

    as i came with another way, i let you know...

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

    if name == 'main': line = input() result = split_and_join(line) print(result)