【发布时间】:2018-10-26 11:06:09
【问题描述】:
我在list1:"management consultancy services better financial health"中设置了一些词
user_search="management consultancy services better financial health"
user_split = nltk.word_tokenize(user_search)
user_length=len(user_split)
分配:管理=1,咨询=2,服务=3,更好=4,财务=5,健康=6。 然后将其与一组列表进行比较。
list2: ['us',
'paleri',
'home',
'us',
'consulting',
'services',
'market',
'research',
'analysis',
'project',
'feasibility',
'studies',
'market',
'strategy',
'business',
'plan',
'model',
'health',
'human' etc..]
因此,任何匹配都会反映在相应的位置上,如 1,2 3 等。如果位置不匹配,则位置将用单词上的数字 6 填充。 预期输出示例:
[1] 7 8 9 10 11 3 12 13 14 15 16 17 18 19 20 21 22 6 23 24
这意味着字符串 3 和 4,即。此列表中有服务和健康(匹配)。其他数字表示不匹配。user_length=6。所以不匹配的位置将从7开始。如何在python中得到这样的预期结果?
【问题讨论】:
标签: python string python-3.x nltk counter