import os
import random
import numpy as np
# file1 = open("C:\\Users\\lgy\Desktop\\fsdownload\\valid-unseen.txt",'r',encoding='utf-8')
file = open("G:\\dataset\\data\\MOH-X\\MOH-X_formatted_svo_cleaned.csv",'r')
# filec = open("D:\\dataset\\cortrain.txt",'a+')
lines = file.readlines()
# lentrain = len(lines)
uniquewords = set()#set无序不可重复类型
d={}
for line in lines:
word = line.strip().split(",")[2]
if(word == "verb"):
continue#结束本次循环,开始下次循环
uniquewords.add(word)
if word in d: #如果d字典中有word这个key
d[word] = d[word]+1 # 这个key的value+1
else:
d[word]=1 # 没有这个key,以word:1键值对加入字典
# print(d)
keys = list(d.keys())
values = list(d.values())
print(values)
print ("list1 最大元素值 : ", np.max(values))
python dict使用
最新推荐文章于 2024-07-13 09:39:43 发布