0

I have a list of urls:

urls = ['http://url1', 'http://url2', 'http://url3']

Mind you the list can have any number of entries including 0 (none). I want to create new node property for each url (list entry). Example how the node will look like

(label{name='something', url1='http://url1', url2='http://url2'}, etc...)

It is possible to expand a dictionary with ** with the same effect I need but is there any way to do this with a list?

abruski
  • 851
  • 3
  • 10
  • 27
  • Possible duplicate of [\*args and \*\*kwargs?](http://stackoverflow.com/questions/3394835/args-and-kwargs) – Erica Jan 06 '16 at 14:37
  • See also http://stackoverflow.com/questions/7745952/python-expand-list-to-function-arguments – Erica Jan 06 '16 at 14:37

1 Answers1

2

You can put your list in a dictionary and use this to create a node:

from py2neo import Node

urls = ['http://1', 'http://2']

props = {}

for i, url in enumerate(urls):
    # get a key like 'url1' 
    prop_key = 'url' + str(i)               
    props[prop_key] = url

my_node = Node('Person', **props)

graph.create(my_node)
Martin Preusse
  • 9,151
  • 12
  • 48
  • 80