Writing a Carbon footprint instance parameter to elements

I’m trying to compute the carbon footprint of an element and writing it back into an instance parameter.

The code needs to do the following:
Look at the name in the first list and then multiply the corresponding volume value in the second list with the correct factors. I created two lists to be able to better follow the output. The lists represent 3 wall elements, each having various layers and each layer has a material and volume. Eg. Wall 1 will have a conc, steel and timb layer with 5.1 ,5.2 ,5.3 as the respective volumes.

I’m trying to get the for-loops to take an element, determine the impact of that element (stored in results() ) and store the impact of each respective element in the outlist. However, I can’t seem to be getting it to work.

Would really appreciate some help as i’ve been trying to get this to work for days, I’ve got a java coding background but can’t seem to figure this out in python.

You can use python dictionaries just like you´d use node dictionaries.

Since you have a background in java, you´ll have a great time learning more python.
Here for copy&paste:

# Dictionary to look up material density
# dictionary = { key1:value1, key2:value2 }
density = {
	'conc': 1,
	'steel': 2,
	'timb': 0.1

# empty result container
outlist = []

for mats, vols in zip(matlist, volume):
	# Temporary container for 1st sublist
	temp = []

	for m, v in zip(mats, vols):

		# density[m] <-- looks up key 'm' in dictionary 'density'
		# and returns its value
		temp.append(v * density[m])


OUT = outlist
1 Like

Hey @Hiko, thank you, really appreciate it. It was so easy to conceptualise it, but I couldn’t get it to work. Eager to learn more python, but my learning curve is struggling to keep up with all the work I’m doing.

Anyways, thanks for the help its precisely what I needed. Really nice knowing there’s a community out there willing to help