我有一个列表列表,如下所示。
mylist = [[5274919, ["report", "porcelain", "firing", "technic"]], [5274920, ["implantology", "dentistry"]], [5274921, ["method", "recognition", "long", "standing", "root", "perforation", "molar"]], [5274923, ["exogenic", "endogenic", "cause", "tooth", "jaw", "anomaly", "method", "standing"]]]
我也有如下概念清单。
myconcepts = ["method", "standing"]
我想看看myconcepts
中的每个概念在mylist
中有多少次。即;]]
"method" = 2 times "standing" = 2 times
我当前的代码如下。
mycounting = 0 for concept in myconcepts: for item in mylist: if concept in item[1]: mycounting = mycounting + 1 print(mycounting)
但是,我目前的
mylist
非常大,大约有500万条记录。myconcepts
列表包含大约10000个概念。
在我当前的代码中,一个概念要花费将近1分钟才能获得count
,这非常慢。
我想知道在python中执行此操作的最有效方法?
出于测试目的,我将数据集的一小部分附加到:https://drive.google.com/file/d/1z6FsBtLyDZClod9hK8nK4syivZToa7ps/view?usp=sharing
如果需要,我很乐意提供更多详细信息。
我有一个清单清单,如下。 mylist = [[5274919,[“报告”,“瓷器”,“射击”,“技术”]],[5274920,[“种植学”,“牙科”]],[5274921,[“方法”,“认可” ,“长”,“站立”,“ ...
您可以拼合输入,然后使用collections.Counter
: