There are many suggestions but I can't make it stick. The closest solution I have below. The data is like:
my_list = ([1, [2, 3], 4, [5, [6 , [], [8, 9]], 10]], 8)
and a function
def convert(G, l, d):
z = []
if isinstance(x, list):
print(x)
z.append(convert(G, x, d))
else:
print(x)
z.append([v[d] for n,v in G.nodes(data=True) if n == l])
return z
execution:
print(convert(G, my_list, "name"))
It gives empty array but print(x) gets the source as is. I'm close I guess. The problem is I don't know how to pass l at if n == l as a integer not list.
EDIT
Outpit:
(['a', ['b', 'c'], 'd', ['e', ['f' , [], ['g', 'h']], 'j']], 'g)
in the same format (nested). The custom function just takes each element (int) and returns its attribute from dict (letter).
Another try:
my_list = ([1, [2, 3], 4, [5, [6 , [], [8, 9]], 10]], 8)
z = []
def convert(G, l, d):
z.append([convert(G, x, d) if isinstance(x, list) else [v[d] for n,v in G.nodes(data=True) if n == x]])
return z
z = convert(G, my_`list, "name")
print(z)
This part is a custom function:
[v[d] for n,v in G.nodes(data=True) if n == l]
so G can be whatever. You can take it as [...]
For example: G.nodes = {0: {'name': 'a'}, 1: {'name': 'b'}, 2: {'name': 'c'}, 3: {'name': 'd'}}
G? As @Peter.k mentioned, what do you expect the output to be?mapfunction for nested lists?