def decrypt(string):
lower = [i for i in range(len(string)) if string[i].islower()]
found = []
for i in range(1, len(lower) - 1): # 这里没有检测头尾
if 4 == lower[i] - lower[i - 1] == lower[i + 1] - lower[i]:
if '\n' not in string[lower[i] - 3:lower[i] + 4]:
found.append(string[lower[i]])
print(''.join(found))
解法二:模拟
string = """..."""
res = []
target = -1
left = mid = right = 0
for i, s in enumerate(string):
if s.islower():
if right == 3:
res.append(string[target])
target = i
mid, right = 1, 0
elif 0 < right < 3:
left = mid = right = 0
elif left == 3:
if not mid:
mid = 1
target = i
else:
left = mid = 0
elif left < 3:
left = 0
elif s.isupper():
if right == 3:
left, mid, right = -1, 0, 0
elif 0 < right < 3:
right += 1
elif mid:
right = 1
elif left == 3:
left = -1
elif -1 < left < 3:
left += 1
print(''.join(res))