Simpler Method to Assigning Sub-Packages based on specific numbering

Is there a quicker way to write this? We have a numbering system between electrical, mechanical, public health, then seperate numbers to suit…
So the script below basically does this, but as you can see i’ll probably have to copy and paste it around 20 times, i’d rather not.

Any advice would be great, i’m not overly familiar with writing codeblocks or python scripting which is how i presume this would be done, so if anyone could at least point me in the right direction i’d really appreciate it.

Thanks