密码压缩 collections
Cypher zip collections
如果我有两个 collections,我该如何将它们压缩在一起?
with [1,2,3] as nums, ['a', 'b', 'c'] as letters
... wat do? ...
return zipped // [{a: 1}, {b: 2}, {c: 3}]
可能无法动态分配地图键(例如,使用 letters
中的项目)。但是这个查询将 return 类似于你想要的东西(使用集合而不是地图):
WITH [1,2,3] as nums, ['a', 'b', 'c'] as letters
RETURN EXTRACT(i IN RANGE(0, LENGTH(nums) - 1) | [letters[i], nums[i]]) AS result;
结果是:
[["a",1],["b",2],["c",3]]
如果我有两个 collections,我该如何将它们压缩在一起?
with [1,2,3] as nums, ['a', 'b', 'c'] as letters
... wat do? ...
return zipped // [{a: 1}, {b: 2}, {c: 3}]
可能无法动态分配地图键(例如,使用 letters
中的项目)。但是这个查询将 return 类似于你想要的东西(使用集合而不是地图):
WITH [1,2,3] as nums, ['a', 'b', 'c'] as letters
RETURN EXTRACT(i IN RANGE(0, LENGTH(nums) - 1) | [letters[i], nums[i]]) AS result;
结果是:
[["a",1],["b",2],["c",3]]