Python 询问如何从数组列表中自动获取单词

Python 询问如何从数组列表中自动获取单词,python,python-2.7,Python,Python 2.7,作为标题,我使用网络爬虫diigo,并且有许多列表,我成为集合()的列表。如下所示: data = [ ['spanish', 'web2.0', 'e-learning', 'education', 'social', 'spain', 'tools', 'learning', 'google', 'e-learning2.0'], ['education', 'technology', 'learning', 'classroom', 'students', 'web2.0'], ['e

作为标题,我使用网络爬虫diigo,并且有许多列表,我成为集合()的列表。如下所示:

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"]))

数据有很多标记,我想这样做->打印(len(search_table[“technology”)当你处理列表时,你可以使用数字访问列表中的元素,这样你就不需要更改单词“code”。您只需这样访问它:

>>> user_data = ['code','java','learn']
>>> user_data[0]
'code'
>>> 
通常,当您访问诸如user_data[“code”]之类的元素时,这是因为您访问字典的键,如下所示:

>>> user_data = {'code':'java, python, ruby'}
>>> user_data['code']
'java, python, ruby'
根据您存储信息的方式,将影响您访问存储信息的方式。考虑到您有用户数据,您可能希望将其存储在字典中的列表中,如:

[
  {'name': 'bob', 'code': 'java, python', 'school':'StackOU'},
  {'name': 'bobina', ...
]
您可以使用bob的编码技能,如:

>>> user_data = [
...       {'name': 'bob', 'code': 'java, python', 'school':'StackOU'},
...     ]
>>> user_data[0]['code']
'java, python'

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

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

将首先打印
搜索表[“技术”]
中的项目数,然后打印
搜索表[“教室”]
中的项目数

对不起,我不知道你在说什么。你能试着重新表述你的问题吗?也许可以展示一些示例输入和预期输出来说明您的问题?@TimPietzcker抱歉,我有个问题,希望您知道我说的话!谢谢你的回答!!我换个问题,你知道怎么做吗?
user_data = ["technology", "classroom"]
for u in user_data:
    print(len(search_table[u]))