lolamontes69

Python/ Python Challenge 3

May 19th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. list1 = []
  2. list2 = []
  3.  
  4. fin = open('foobar.txt')
  5. for line in fin:
  6.     for a in line:
  7.         if a.isupper():
  8.             list1.append("0")
  9.             list2.append(a)
  10.         elif a.islower():
  11.             list1.append("1")
  12.             list2.append(a)
  13.  
  14. converted = ''.join(list1)
  15. unconverted = ''.join(list2)
  16.  
  17. win = converted.find('100010001')
  18. print unconverted[win+1:win+8]
  19.  
  20. def find_all(a_str, sub):
  21.     start = 0
  22.     while True:
  23.         start = a_str.find(sub, start)
  24.         if start == -1: return
  25.         yield start
  26.         start += len(sub)
  27.  
  28. win1 = list(find_all(converted, '100010001')) # [0, 5, 10, 15]
  29. for a in win1: print unconverted[a:a+9]
Advertisement
Add Comment
Please, Sign In to add comment