# Reorganize List

#1

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)

At the end it should be:

1 List
0 - 12
1 - X
2 - X

2 List
0 - 32
1 - X
2 - X

Regards

0 Likes

#2

try a transpose node

0 Likes

#3

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

1 Like

#4

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

#5

@Cree-G Just another way with OOTB nodes

2 Likes

#6

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

#7

Hi guys, i have a next level problem for you

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

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

0 Likes

#8

List.getitematidex using list levels

1 Like

#9

@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.

0 Likes

#11

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

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

0 Likes

#12

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

0 Likes

#13

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

0 Likes

#14

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

0 Likes

#15

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

0 Likes

#16

HI

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

Then the Python fails

Kind regards

0 Likes

#17

OK I have it!

Kind regards

0 Likes