[Pregunta] List of Tuples [Guardado]


Hi everyone.
I would like to search in a list of tuple and find a value corresponding to a specific index, is there anyone who can explain to me how to access tuple?

In particular, I'm trying to access the tuple list generated from GetObjectAttributes node.

Thanks in advance for any suggestion!

Adjuntos (1)

Type: image/jpeg
Descargado 173 veces
Size: 210,19 KiB

Show solution Hide solution

Currently, it seems we don't have the node for access a normal tuple. We only have one for named tuple...

But for this you can try to write py code. Copy & paste the code below into the node "ExecPythonScript" and connect both tuple lists and index value to the 'parameter' of that node. Make sure you first connect the tuple list and then the index, because the order does matter. You should be able to get the results you want. (Make sure the number of list levels is the same as shown in your screenshot, otherwise it won't work.)

def function_to_execute(tuple_list,search_value):   
    result = []
    result.extend([t[1] for t in tuple_list if t[0] == search_value])
    return result

This code just does what you describe. If the 1st value in the tuple is equal to the index you provide, it will then return the 2nd value of the tuple back.
For more info, please check the screenshot attached.

Product Owner API, Allplan GmbH

Adjuntos (1)

Type: image/png
Descargado 184 veces
Size: 65,43 KiB

Currently, it seems we don't have the node for access a normal tuple. We only have one for named tuple...

But for this you can try to write py code. Copy & paste the code below into the node "ExecPythonScript" and connect both tuple lists and index value to the 'parameter' of that node. Make sure you first connect the tuple list and then the index, because the order does matter. You should be able to get the results you want. (Make sure the number of list levels is the same as shown in your screenshot, otherwise it won't work.)

def function_to_execute(tuple_list,search_value):   
    result = []
    result.extend([t[1] for t in tuple_list if t[0] == search_value])
    return result

This code just does what you describe. If the 1st value in the tuple is equal to the index you provide, it will then return the 2nd value of the tuple back.
For more info, please check the screenshot attached.

Product Owner API, Allplan GmbH

Adjuntos (1)

Type: image/png
Descargado 184 veces
Size: 65,43 KiB

Great, this is what I needed!
Thanks


https://campus.allplan.com/ utiliza cookies  -  Aqui

Acéptalo