-1

I have a code that looks something like this

import re

node_list = ["/robot_state_publisher", "/test", "/ok", "/node_1", "/node", "/node_2"]
blacklist_nodes = ["/robot_state_publisher", "/node"]

blacklist_nodes = list(set([node_name for node_name in node_list for b in blacklist_nodes if bool(re.match(b, node_name))]))

print(blacklist_nodes)

The output of this is

['/node_1', '/robot_state_publisher', '/node', '/node_2']

but my goal is that, if in the blacklist_nodes list, I passed in /node, I want to only get /node from the node_list and ignore all the /node_1 and /node_2.The main reason why I am using RE in my implementation is because if I passed in /node*, I want to get the /node, /node_1 and /node_2 but I am a bit struggling in trying to only get /node in this current implementation since it gets all the unnecessary nodes I do not need.

Note : I do know I can do /node$ in my blacklist_nodes and this will get me the output I need but I want to only pass in /node.

Is there any way I could possibly do this? Cheers

0 Answers0