Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypher zip collections

Tags:

neo4j

cypher

If I have two collections, how might I zip them together?

with [1,2,3] as nums, ['a', 'b', 'c'] as letters
... wat do? ...
return zipped // [{a: 1}, {b: 2}, {c: 3}]
like image 270
Brian Gates Avatar asked Apr 28 '26 08:04

Brian Gates


1 Answers

It may not be possible to dynamically assign map keys (e.g., using the items in letters). But this query will return something similar to what you want (using collections instead of maps):

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;

The result is:

[["a",1],["b",2],["c",3]] 
like image 170
cybersam Avatar answered May 01 '26 16:05

cybersam