How do I extract values from Dictionary.ByKeysValues

Hello, I am trying to extract corresponding [Values] based on the [Keys] that I feed into the dictionary [Search Keys].

Now, the [Keys] that I am trying to feed in is a pair of [true, false]. For example, the value will return as 1 if the pair is [true,false], as 2 if [false,true], as 3 if [true, true] etc… Could you please guide me if there’s a way to achieve that outcome?

Thank you very very much

Hi
dictionary keys in dynamo are strings normally

Sincerely
christian.stan

1 Like

hi Christian,

I tried converting the True/False Boolean to String to make it work for the Dictionary.ByKeysValues but I still don’t get the outcomes I am looking for…

The key needs to be a single entity. The returned value can be a single item or a list, but the identifier (key) needs to be a singular unique object. The suggestion to stringify your key is meant to convert any list into a single string value.

Your specific case of true/false values is probably better suited for just a nested conditional statement.

2 Likes

import sys
import clr
entrant=IN[0]
out=[]
for e in entrant:
    if e.count(True) == len(e):
        out.append(1)
    if e.count(False) == len(e):
        out.append(3)
    else:
        out.append(2)
OUT = out

definitely needs to be improved
sincerely
christian.stan

1 Like

ah I totally understood what @christian.stan meant now. I stringified them and got the outcome I expected now. Thank you very much

1 Like

hi Christian,

Thank you very much for your guidance. I misinterpreted your other comment but it works perfectly now.

Kind regards,

1 Like