from tqdm import tqdm
import os
import pickle
import itertools

pkl_dir="./data/pkl/pinyin_pkl(1)"

for file in tqdm(os.listdir(pkl_dir)):
        # print("filename:{}".format(file))
        contents = pickle.load(open(os.path.join(pkl_dir,file),"rb"))
        # contents=random.sample(contents,10)

        # print(contents)
        # contents=[list(itertools.chain.from_iterable(lines)) for lines in contents]
        # contents=list(itertools.chain.from_iterable(contents))

        with open(os.path.join("data/pkl/pinyin_pkl_txt",file[:-4]+".txt"),"w",encoding="utf-8") as f:
            f.write(" ".join(contents))
