Advertisement
davide1409

new_format

Nov 25th, 2019
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. def new_format(T,F):
  2. #@param T: text with style
  3. #@param F: format
  4.   stili = ["italics", "plain", "bold", "underlined"] #stili possibili
  5.  
  6.   if (F[0] not in stili) or ( (F[1]>=len(T[0])) or (F[2]>=len(T[0])) ) or (F[1]<0 or F[2]<=0):
  7.     pass
  8.  
  9.   else:
  10.     flag = 0
  11.     for i in range(1,len(T)):
  12.       if(T[i][0] == F[0]):
  13.         if (F[1]>=T[i][1] and F[1]<=T[i][2]) or (F[2]<=T[i][2] and F[2]>=T[i][1]) or ( not( (F[1]>T[i][2]) or (F[2]<T[i][1]) ) ):
  14.           T[i][1] = min(T[i][1], F[1])
  15.           T[i][2] = max(T[i][2], F[2])
  16.        
  17.         else:
  18.           flag+=1
  19.      
  20.       else:
  21.         flag+=1
  22.        
  23.  
  24.     if flag == len(T[1:]):
  25.       T.append(F)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement