Reorganize List

HI

I’m new in Dynamo and i’m trying to do the following in the attached List.

1: Join the lists with the same Indice 0
2: Sum the values from the Indice 1 (with the same Indice 0)
3: Sum the values from the Indice 2 (with the same Indice 0)

List

At the end it should be:

1 List
0 - 12
1 - X
2 - X

2 List
0 - 32
1 - X
2 - X

Please Need a Little help.

Regards

try a transpose node

There might be a better method using nodes but this should work:

1 Like

A python version however this will sort it based on the first item in the lists in alphanumeric order.

data = IN[0]
keys = set([key[0] for key in data])
outdata = {key: [0,0] for key in keys}

for dat in data:
	temp = outdata[dat[0]]
	temp[0] += dat[1]
	temp[1] += dat[2]
	outdata[dat[0]] = temp


OUT = outdata.items()
1 Like

@Cree-G Just another way with OOTB nodes

2 Likes

HI

This is perfect!!! Thanks for the help!!!

First time I Python use ;)…

I just made a crash course last week and will need a little more help in the future XD.

Best regards

Christian

1 Like

Hi guys, i have a next level problem for you :wink:

Need to combine 0 of list 0 with 0 of list 1 and 0 of list 2 with 0 of list 3 etc …

Thanks in advance for your help.

If you want to see the full problems this is the link of the topic :

List.getitematidex using list levels

1 Like

@Jonathan.Olesen’s suggestion should work. Alternatively, if the nested lists are the same size, you can use List.Transpose and then sum the first list.

When i use list.transpose, the function transpose z axes and not x axes.

Traverses_10

I don’t want that transpose but that :
list 0
x = 26; y = 0; z = 26
x = 1474; y = 0; z = 26

list 1
x = 26; y = 0; z = 1526
x = 1474; y = 0; z = 1526

Have you tried my suggestion, it will accomplish what you’re looking for :wink:

@Jonathan.Olesen Yes i did but don’t who to input in index

Well if you want index 0 from both lists, you input index 0, the key here is to use list levels :wink:

Hi everyone, I found a solution for my problem.

List.getitematindex work correctly but not in my case.

Remind the initial problem :
Can correctly merge two list of point in case of list “level”.

As you can see, on the screenshot, my point exit are in this form :

list
__list 0
____x = … ; y = … ; z = …
__list 1
____x = … ; y = … ; z = …

If you use list.transpose in this case you don’t obtain the points you need to place your adaptive component with two point.

To place your adaptive component by two point you need that type of form :

__list 0
____x = … ; y = … ; z = …
____x = … ; y = … ; z = …
__list 1
____x = … ; y = … ; z = …
____x = … ; y = … ; z = …

To delete a “level” of list you need flaten node in exit of point.bycoordonate to get this :

list
__x = … ; y = … ; z = …
__x = … ; y = … ; z = …
__x = … ; y = … ; z = …
__x = … ; y = … ; z = …

Now if you transpose this type of list you obtain that :

__list 0
____x = … ; y = … ; z = …
____x = … ; y = … ; z = …
__list 1
____x = … ; y = … ; z = …
____x = … ; y = … ; z = …

This is the dynamo of the solution :

Fact :

Flaten remoove you a level of list in a list. It can also delete null value of a list.

list.transpose work like this (bold is enter, green is the exit)

I hope this final post will be helpfull for us !

See you soon on forum.dynamobim.com

HI

Just realized that i have empty items. How can i replace them with 0

Then the Python fails :sob:

Please help :slight_smile:

Kind regards

OK I have it!

Kind regards