def groups_to_columns(lines):
directions = ['north', 'south', 'west', 'east']
current_direction = None
for line in lines:
data = line.strip()
if data in directions:
current_direction = data
else:
yield current_direction, data
with open('data.txt') as fh:
for direction, camera in groups_to_columns(fh):
# Запись в xls