Advertisement
ilyakanyshev

Untitled

Apr 17th, 2020
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. from copy import copy
  2. from time import time
  3.  
  4.  
  5.  
  6. def commandSplit(text):
  7.     results = [[""],[""]]
  8.     count = 1
  9.     countChars = 0
  10.     countSimvols = 0
  11.     for char in text:
  12.         countSimvols += 1
  13.         if char.lower() in 'qwertyuioplkjhgfdsazxcvbnmйцукенгшщзхъэждлорпавыфячсмитьбю':
  14.             countChars += 1
  15.         if count == 2:
  16.             if char == ']':
  17.                 count -= 1
  18.                 results[0][-1] += "]"
  19.                 results[0].append("")
  20.             else:
  21.                 results[0][-1] += char.lower()
  22.                 if char == " ":
  23.                     results[1].append("")
  24.                 else:
  25.                     results[1][-1] += char.lower()
  26.         else:
  27.             if char == "[":
  28.                 count += 1
  29.                 tmp = copy(results[0])
  30.                 tmp[-1] += char.lower()
  31.                 results[1] = tmp
  32.                 if results[0][-1] != "":
  33.                     results[0].append(char.lower())
  34.                 else:
  35.                     results[0][-1] += char.lower()
  36.             elif char == " ":
  37.                 results[0].append("")
  38.             else:
  39.                 results[0][-1] += char.lower()
  40.     results.append("")
  41.     return {
  42.         'countChars': countChars,
  43.         'countSimvols': countSimvols,
  44.         'result':  results[count-1],
  45.     }
  46.  
  47.  
  48. tests = [
  49.     "Hello, [id1|Pavel Durov]",
  50.     "Hello, [id1|Pavel Durov",
  51.     "Hello, [id1 Pavel Durov]",
  52.     "Hello, id1|Pavel Durov]",
  53.     "Hello, [id1|Pavel Durov[]]",
  54.     "[id1|Pavel Durov], hello!",
  55.     "[id1|Pavel Durov], hello, [id1|Pavel Durov]!",
  56.     4000*"["
  57.     ]
  58.  
  59.  
  60. for number, test in enumerate(tests):
  61.     start_time = time()
  62.     print("Test#{number}".format(number=number))
  63.     print("  Text:\t ", test)
  64.     print("  Result:", commandSplit(test))
  65.     print("  Time:\t ", time()-start_time, "\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement