filename = r"D:\temp\units.txt"
# 设置一个从excel文件复制出来的txt
# 每一行的格式如下: <题号>\t<对应单元(若干位0-9的数字)>

taglist = ["暂无对应","第一单元","第二单元","第三单元","第四单元","第五单元","第六单元","第七单元","第八单元","第九单元"]
with open(filename,"r",encoding = "u8") as f:
    data = f.read()
pros = data.strip().split("\n")
dic= {}
for p in pros:
    a,b=p.split("\t")
    dic[a] = ""
    for t in b:
        dic[a] += taglist[int(t)]+"\n"
output = "tags\n\n"
for d in dic:
    output += d + "\n"
    output += dic[d] + "\n\n"
with open(r"文本文件\metadata.txt","w",encoding = "u8") as f:
    f.write(output)