forked from sanjaypradeep/Python-Data-Structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringSplitAndJoin.py
More file actions
37 lines (34 loc) · 769 Bytes
/
StringSplitAndJoin.py
File metadata and controls
37 lines (34 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
__author__ = 'Sanjay'
# 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.
#
# Input Format
# The first line contains a string consisting of space separated words.
#
# Output Format
# Print the formatted string as explained above.
#
# Sample Input
#
# this is a string
# Sample Output
#
# this-is-a-string
userInput = input()
# solution 1:
print (userInput.replace(" ", "-"))
# Solution 2:
print ("-".join(userInput.split()))