In this Re.split() problem, You are given a string S consisting only of digits 0-9, commas,, and dots. Your task is to complete the regex_pattern defined below, which will be used to re.split() all of them , and . symbols in S. It’s guaranteed that every comma and every dot in S is preceded and followed by a digit.

HackerRank Re.split() solution in python


Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

import re
a = re.split("[,.]",raw_input())

for k in a:
    if k.isdigit(): print k


Problem solution in Python 3 programming.

import re
s = input()
for t in re.split(r",|\.", s):
    if t != '': print(t)


Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re 
for item in re.split("[,.]", raw_input()):
    if item:
        print item


Problem solution in pypy3 programming.

import re
# Enter your code here. Read input from STDIN. Print output to STDOUT
s = input().strip()

l = re.split(r"[,\.]+",s)

for x in l:
    if x != "":
        print(x)