Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. texts = [['a','a','b'], ['a','a','a','b','b','c'], ['b','a','b'], ['a','c','a','b','a','b']]
  2.  
  3. for text in texts:
  4.  
  5.     highest = 1
  6.     thing = {highest: []}
  7.  
  8.     for t in text:
  9.         found = False
  10.         for h in xrange(highest, 0, -1):
  11.             if h == 0:
  12.                 continue
  13.             for x in thing[h]:
  14.                 if found:
  15.                     break
  16.                 if x == t:
  17.                     found = True
  18.                     if highest == h:
  19.                         highest+=1
  20.                         thing[highest] = []
  21.                     thing[h+1].append(t)
  22.  
  23.             if found:
  24.                 while t in thing[h]:
  25.                     thing[h].remove(t)
  26.                     thing[h+1].append(t)
  27.  
  28.         if not found:
  29.             thing[1].append(t)
  30.  
  31.     print thing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement