Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open('3bigbodyguards.txt') as f:
- string = f.read()
- lines = string.split('\n')
- answer = []
- line_index = 0
- for l in lines:
- char_index = 0
- end_of_line = len(l) - 1
- buddyCount = 0
- for c in l:
- buddyCount = 0
- #skip if its uppercase
- if c.istitle():
- pass
- #check for buddies
- else:
- #if he isn't first in line, check neighbor to left:
- if char_index > 2:
- if l[char_index -1].istitle() and l[char_index -2].istitle() and l[char_index -3].istitle() :
- if char_index > 3:
- if not l[char_index -4].istitle() :
- buddyCount += 1
- elif char_index == 3:
- buddyCount +=1
- #if he isn't the last in line, check neighbor to right:
- if(char_index < end_of_line - 2):
- if l[char_index +1].istitle() and l[char_index +2].istitle() and l[char_index +3].istitle():
- if char_index < len(l) - 4:
- if not l[char_index +4].istitle() :
- buddyCount += 1
- elif char_index == len(l) - 3:
- buddyCount +=1
- if(buddyCount == 2):
- answer.append(c)
- char_index += 1
- line_index += 1
- answerstring = ''
- for x in answer:
- answerstring += x
- print(answerstring)
Add Comment
Please, Sign In to add comment