var select = React.findDOMNode(this.refs.selectRef);
var values = [].filter.call(select.options, function (o) {
return o.selected;
}).map(function (o) {
return o.value;
});
这段代码为文件中的所有行创建了bigrams,但我需要的是每行单独的bigrams,即,biterms列表中的每个项目都是bigrams。有人可以帮忙吗?
答案 0 :(得分:2)
你需要迭代每一行。
biterms = u'''Difensori dei diritti umani, libertà di espressione > Human rights defenders, freedom of expression
sgomberi forzati, violazioni dei diritti umani > forced evictions, human rights violations'''.splitlines()
bigrams = []
for line in biterms:
l = []
trans = line.split(' > ')
left = trans[0].split(', ')
right = trans[1].split(', ')
for i in left:
for j in right:
l.append((i, j))
bigrams.append(l)
for g in bigrams:
print g