Somating according to another list

Hi,

I’m trying to make a sum, almost like a VLOOKUP in Excel… according a element.id.

I’m almost certain someone can pull this off with OOTB nodes, but I need python for this:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
listin = IN[0]

ids = [x[0] for x in listin]
idset = set(ids)	

diction = {}
for id in idset:
	diction[id] = 0

for x in listin:
	diction[x[0]] += x[1]
#Assign your output to the OUT variable.
OUT = diction.keys(), diction.values()
1 Like

Hey,

I think you answered another topic that i posted kkkkkk…

I posted two topics in almost the same time, but differentes topics

Anyway, thanks, to the other topic it working!

Haha okay, I see, but it’s basically the same question right?

No,
This topic is about 2 lists, the other, is about only one.

I helped me with the other, but in this situation, i didn’t find a way yet…

Ah yes now I see.

If you can get your keys and values aligned like this:

Then you could use the attached python code.

Sum across lists by key.dyn (11.1 KB)

20170809-220170809-2.dyn (9.9 KB)

1 Like

I’m sorry,

I wrote wrong… is almost what you did, but, i forgot to say that, the second list, can be have two or more equal elements, example below:

image

Not sure, if I understand the intent, maybe something like this…
20170810-1.dyn (13.2 KB)

Not working…
but, dont worry, i made by another way, a lot of nodes bot it’s working… hahaha.

Thanks a lot!

1 Like

@daniel.petrin Hello, I have a similar problem. Can you show me how you solved it?