我在javascript中重写了一些Python代码,我遇到了一些奇怪的事情。我确定我忽略了一些愚蠢的东西,但似乎它返回了一个逗号分隔的字符串,我期待一个数组。
蟒:
triples = [('one', 'two', 'three'), (...), ... ]
for w1, w2, w3 in triples:
key = (w1, w2)
if key in self.cache:
self.cache[key].append(w3)
else:
self.cache[key] = [w3]
返回:
('of', 'Thee,'): ['Sailing', 'Light'],
('meat', 'within'): ['is'],
的javascript:
for (var i=0; i<=triples.length; i++) {
if (triples[i]) {
var key = [triples[i][0], triples[i][1]];
if (key in this.cache) {
this.cache[key].push(triples[i][2]);
} else {
this.cache[key] = [];
this.cache[key].push(triples[i][2]);
}
}
}
返回:
'you,estimated,': [ 'and', 'and' ],
'estimated,,and': [ 'far', 'far' ],