gpt4 book ai didi

python - 问如何自动从数组列表中抓取单词

转载 作者:太空宇宙 更新时间:2023-11-03 17:00:57 24 4
gpt4 key购买 nike

作为标题,我对 diigo 进行网络爬虫,并且有很多列表,我将列表添加到 set() 中。如下所示:

data = [ ['spanish', 'web2.0', 'e-learning', 'education', 'social', 'spain', 'tools', 'learning', 'google', 'e-learning2.0'],   ['education', 'technology', 'learning', 'classroom', 'students', 'web2.0'], ['education'],  ['technology'] ]

并进行一些计算

search_table = {}

for i, tag_list in enumerate(data):
for tag in tag_list:
if tag not in search_table:
search_table[tag] = set()
search_table[tag].add(i)

# How many people have `technology`?
print(len(search_table["technology"]))
# How many people have `education`?
print(len(search_table["education"]))
# How many people have both `technology`, `education`?
print(len(search_table["technology"] & search_table["education"]))

数据有很多标签,我想这样做 ->print(len(search_table["technology"]))<- 技术可以自动改变下一个世界喜欢类。

我真的不知道该怎么办,我只想到

for u in user_data:

print u

但是如何将世界添加到 print(len(search_table["u "]))

真诚的鲍勃

最佳答案

我想我明白你的意思了。你就快到了:

user_data = ["technology", "classroom"]
for u in user_data:
print(len(search_table[u]))

将首先打印 search_table["technology"] 中的项目数,然后打印 search_table["classroom"] 中的项目数。

关于python - 问如何自动从数组列表中抓取单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34987921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com