python将每一列写入列表
程序员文章站
2024-02-05 09:01:52
# -*- coding: utf-8 -*-
'''
python读取文件,每一列写入一个列表
'''
def rea...
# -*- coding: utf-8 -*- ''' python读取文件,每一列写入一个列表 ''' def read(cor): data = [] with open(cor,encoding='utf-8') as fr: lines = fr.readlines() sent_, pin_, tag_ = [], [], [] for line in lines: if line != '\n': [char, yin, label] = line.strip().split() sent_.append(char) pin_.append(yin) tag_.append(label) elif line == '\n': data.append((sent_, pin_, tag_)) sent_, pin_, tag_ = [], [], [] print(data) return data read('源文件路径')