如果你的檔案是txt file....
我先隨便寫一個給你,不過如果要大量處理這類資料,建議整理成list或pandas中的Series的格式。
file = open('<path/to/your/file>', 'r', encoding='utf8')
collected_list = []
target_list = []
target_item_list = []
for idx, line in enumerate(file):
inner_idx = line.split()[0]
item = line.split()[1]
target_list.append((inner_idx, item))
target_item_list.append(item)
if (idx+1) % 10 == 0:
collect_dict = {}
max_item = max(target_item_list)
max_item_idx = target_item_list.index(max_item)
collected_list.append(target_list[max_item_idx-2:max_item_idx+3])
target_list = []
target_item_list = []
print(collected_list)