我有六个列表,其中三个对应于给定的句子,另外三个列表对应于前面列表的标签。我想根据句子的顺序将这些列表压缩成有序的信息
from collections import OrderedDict
sentence = 'Im fucking excited to learn your damn business'
words = ['excited', 'learn', 'business']
stopwords = ['Im', 'to', 'about', 'your']
swearwords = ['fucking', 'damn']
# Labels
words_labels = ['friendly', 'interested', 'interested']
stopwords_labels = ['stopword'] * len(stopwords)
swearwords_labels = ['sweaword'] * len(swearwords)
d = OrderedDict(zip(keys, values))
# Expected output
{
'Im': 'stopword',
'fucking': 'swearword',
'excited': 'friendly',
'to': 'stopword',
'learn': 'interested',
'your': 'stopword'
'damn': 'swearword',
'business': 'interested'
}
首先要列出重复内容,语法如下
然后建立所有内容和标签的列表,那么你就很好了
您还可以使用该语法,该语法连接
相关问题 更多 >
编程相关推荐