Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. def row_repair(row_to_repair, base_row, regex_text_to_replace, regex_base_text):
  2.     used_items = []
  3.     start_index = 0
  4.  
  5.     while True:
  6.         match_text = match_forward(regex=regex_text_to_replace, iterable=row_to_repair, start=start_index)
  7.  
  8.         if not match_text[0] or start_index >= len(base_row) - 1:
  9.             break
  10.  
  11.         text_to_replace = match_text[0].group(1)
  12.  
  13.         for cell_i in range(start_index, len(base_row)):
  14.             c_cell = base_row[cell_i]
  15.             start_index = cell_i
  16.  
  17.             if c_cell in used_items:
  18.                 break
  19.  
  20.             if re.search(regex_base_text, c_cell, re.I | re.S):
  21.                 try:
  22.                     row_to_repair[cell_i] = text_to_replace
  23.                     used_items.append(c_cell)
  24.                 except IndexError:
  25.                     break
  26.         used_items = []
  27.     return row_to_repair
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement