write a script that takes a colon separated list of items and outputs the item one per line to standard output without the colons
Answers
Separating String at a Delimiter - Python
We would take a user input string, which is separated by any specific delimiters.
A delimiter is any specific symbol separating the various things. A common delimiter is a comma, which is seen in CSV (Comma Separated Values) files.
Tabs, Spaces, Semicolons and Colons are also common delimiters.
Here, we have colon (:) as a delimiter.
We use Python's string.split(delimiter) function, where we just supply a delimiter and the function splits the strings into a list according to the delimiter.
We then simply loop over the list and display the items.
Program
# Take user input
user_text = input("Enter a string separated by colons: ")
# Split the text at colons
items = user_text.split(":")
# Print out the items
print("The items are:")
for item in items:
print(item)
Sample Run
$ python3 separator.py
Enter a string separated by colons: Hello:Brainly:This:is:QGP
The items are:
Hello
Brainly
This
is
QGP