Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from copy import copy
- from time import time
- def commandSplit(text):
- results = [[""],[""]]
- count = 1
- countChars = 0
- countSimvols = 0
- for char in text:
- countSimvols += 1
- if char.lower() in 'qwertyuioplkjhgfdsazxcvbnmйцукенгшщзхъэждлорпавыфячсмитьбю':
- countChars += 1
- if count == 2:
- if char == ']':
- count -= 1
- results[0][-1] += "]"
- results[0].append("")
- else:
- results[0][-1] += char.lower()
- if char == " ":
- results[1].append("")
- else:
- results[1][-1] += char.lower()
- else:
- if char == "[":
- count += 1
- tmp = copy(results[0])
- tmp[-1] += char.lower()
- results[1] = tmp
- if results[0][-1] != "":
- results[0].append(char.lower())
- else:
- results[0][-1] += char.lower()
- elif char == " ":
- results[0].append("")
- else:
- results[0][-1] += char.lower()
- results.append("")
- return {
- 'countChars': countChars,
- 'countSimvols': countSimvols,
- 'result': results[count-1],
- }
- tests = [
- "Hello, [id1|Pavel Durov]",
- "Hello, [id1|Pavel Durov",
- "Hello, [id1 Pavel Durov]",
- "Hello, id1|Pavel Durov]",
- "Hello, [id1|Pavel Durov[]]",
- "[id1|Pavel Durov], hello!",
- "[id1|Pavel Durov], hello, [id1|Pavel Durov]!",
- 4000*"["
- ]
- for number, test in enumerate(tests):
- start_time = time()
- print("Test#{number}".format(number=number))
- print(" Text:\t ", test)
- print(" Result:", commandSplit(test))
- print(" Time:\t ", time()-start_time, "\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement