Yes (YAML is extremely flexible this way); it would look like
constraints: [node.role == worker, node.hostname != worker3, node.hostname != worker4]
My loose experience from other contexts that use YAML (Kubernetes, Ansible) is that the inline form is much easier to read and write if you have single words, but worse if things run over a line; for this example I’d definitely use the block form as you have it originally.
I’ve only rarely seen the YAML reference syntax used at all and I’d probably avoid it in practice, even if you are repeating the same thing over and over. (You can, but nobody will recognize what the * and & are doing there.)
In Kubernetes land the general practice is for the YAML files to not be clever at all, but to use some sort of external templating system to create them. The Helm tool uses Go’s templating system, for instance. There you can get arbitrarily clever, with a usability/maintainability tradeoff. I’m not immediately aware of anything equivalent for Docker Compose, though I’m sure it exists.