Matt23

Kompresja

Mar 12th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import re
  2.  
  3. def compress():
  4.     texts = ["AndrzejAndrzej", "TomekTomek", "AndyAnd", "KamilKmail", "KasiaKasia"]
  5.     for text in texts:
  6.         if len(text) % 2 is 0:
  7.             half = len(text) / 2
  8.             if text[:half] == text[half:]:
  9.                 print "({0})".format(text[:half])
  10.  
  11. def uncompress():
  12.     uncompressed = ""
  13.     group = ""
  14.  
  15.     texts = ["Anr(z)e(jek)", "(Ka)mil(os)", "Domi(nn)ik(awe)"]
  16.     for text in texts:
  17.         for i, c in enumerate(text):
  18.             if c is not '(' and c is not ')':
  19.                 uncompressed += c
  20.             if c is '(':
  21.                 while text[i+1] is not ')':
  22.                     group += text
  23.         print uncompressed
  24.         uncompressed = ""
  25.  
  26. uncompress()
Advertisement
Add Comment
Please, Sign In to add comment