Search code examples
gremlintinkerpoptinkerpop3amazon-neptunegremlinpython

Gremlin Python: Query a list and that returns key/value list


I want to query a list and the query response must return to me which response of the list item.

For example:

a = [1,2,3]

graph.V().has("cid", "value", P.within(a)).in_('o_f_c').out('o_f_c').values().toList()

The response of above query is:

[1232131, 4322334, 124334, 354454, 23423423]

The response which I want is:

[[1, [1232131, 4322334]], 
[2, [124334],
[3, [354454,23423423]]

I just dont want to do that in a for loop with python. Is it possible do with gremlin-python?


Solution

  • I think you just need to group() your results:

    g.V().has("cid", "value", P.within(a)).
      group().
        by('cid').
        by(__.in_('o_f_c').out('o_f_c').values().fold()).
      toList()