From 3ce4dcf393d7eaec4278b4519a458e199e629a4b Mon Sep 17 00:00:00 2001 From: Andrey Blazejuk Date: Sun, 20 Oct 2024 07:44:27 -0300 Subject: [PATCH] Refactor file reading loops to improve efficiency with for-loop iteration --- Kasa/Preprocessing.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Kasa/Preprocessing.py b/Kasa/Preprocessing.py index 0ecf1d7..317d505 100644 --- a/Kasa/Preprocessing.py +++ b/Kasa/Preprocessing.py @@ -15,24 +15,14 @@ def read_parallel_dataset(self,filepath_twi='../data/jw300.en-tw.tw', # read english data english_data = [] with open(filepath_english, encoding='utf-8') as file: - line = file.readline() - cnt = 1 - while line: + for line in file: english_data.append(line.strip()) - line = file.readline() - cnt += 1 # read twi data twi_data = [] with open(filepath_twi, encoding='utf-8') as file: - - # twi=file.read() - line = file.readline() - cnt = 1 - while line: + for line in file: twi_data.append(line.strip()) - line = file.readline() - cnt += 1 return twi_data,english_data