Replace values in list

Hello everybody,

I’m a beginner at Dynamo and at one point I get stuck.

I want to assign a description to the values in the “List.Flatten” list. For example, 16.55 should be assigned to “B 1100”, 15.05 should be “Type 1” and so on until the complete list is ready.
Is there a possibility how values in a list can be assigned, for example through a kind of comparison?

image

In theory, the end result should look like this:
16.55 B1100
15.05 Type 1
12.4 Type 1
7.8 600 x 400 x 350
16.55 B1100
15.05 Type 1
12.4 Type 1
7.8 600 x 400 x 350
16.55 B1100
15.05 Type 1
12.4 Type 1
7.8 600 x 400 x 350
16.55 B1100
15.05 Type 1
12.4 Type 1
7.8 600 x 400 x 350

Thanks for your help!

You could create a tuple consisting of <key, value> for each of your list items in a for loop.
Afterwards you create a list of these tuples. list[tuplelist][0] = key & list[tuplelist][1] = value.

It depends on what kind of logic you want to connect your keys with your values.

Would the solution also work in the following case?

image

I want a logic that recognizes when a certain number occurs a certain value is assigned.

Some basic approaches.

You could also use a function which returns a value due to some conditions, which you give as an argument to the function.
If you got more conditions you can iterate over a list of keys instead of comparing it with conditions by using many if-statements.

example.dyn (9.5 KB)

1 Like

If you want to assign a second value based on an initial value then you’ll want a dictionary like @d.feyerer showed.
If you want to assign values solely based on list order then you can just replicate your first list to match the length of the second.

Thanks for the quick solution! I think that helps.

1 Like