Invert the selection status of all nodes.
for node in nuke.allNodes(): node["selected"].setValue(not node["selected"].getValue())