Convert nested query to python scripting

Perhaps you are looking for this:

But to echo Paul: Why?