blob: 350bd40aa8ec1ed8b9d33fe61a9d751cef6f055c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/usr/bin/python3
# Challenge 020
#
# Task #1
# Write a script to accept a string from command line and split it on change
# of character. For example, if the string is "ABBCDEEF", then it should split
# like "A", "BB", "C", "D", "EE", "F".
import sys
import re
str = sys.argv[1]
segs = []
while True:
matches = re.match(r"((.)\2*)", str)
if not matches:
break
segs.append(matches.group(1))
str = str[matches.end(0):]
print(", ".join(['"'+x+'"' for x in segs]))
|