Guest User

Untitled

a guest
Jul 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. with open('3bigbodyguards.txt') as f:
  2. string = f.read()
  3. lines = string.split('\n')
  4. answer = []
  5.  
  6.  
  7. line_index = 0
  8. for l in lines:
  9. char_index = 0
  10. end_of_line = len(l) - 1
  11. buddyCount = 0
  12. for c in l:
  13. buddyCount = 0
  14. #skip if its uppercase
  15. if c.istitle():
  16. pass
  17. #check for buddies
  18. else:
  19. #if he isn't first in line, check neighbor to left:
  20. if char_index > 2:
  21. if l[char_index -1].istitle() and l[char_index -2].istitle() and l[char_index -3].istitle() :
  22. if char_index > 3:
  23. if not l[char_index -4].istitle() :
  24. buddyCount += 1
  25. elif char_index == 3:
  26. buddyCount +=1
  27.  
  28. #if he isn't the last in line, check neighbor to right:
  29. if(char_index < end_of_line - 2):
  30. if l[char_index +1].istitle() and l[char_index +2].istitle() and l[char_index +3].istitle():
  31. if char_index < len(l) - 4:
  32. if not l[char_index +4].istitle() :
  33. buddyCount += 1
  34. elif char_index == len(l) - 3:
  35. buddyCount +=1
  36.  
  37. if(buddyCount == 2):
  38. answer.append(c)
  39. char_index += 1
  40. line_index += 1
  41.  
  42.  
  43. answerstring = ''
  44. for x in answer:
  45. answerstring += x
  46. print(answerstring)
Add Comment
Please, Sign In to add comment