More efficient way of doing things with any programming language is using the loops.

https://wiki.python.org/moin/ForLoop

Example of creating 32 vlans on cisco switch :

vlans_loops

The code looks more readable and you can scale it now :)