When assigning many variables, (or simply instantiating), one could do:
list_0, list_1, list_2 = [], [], []
which will make three variables with empty lists.
Hypothetically, if one were to make 1,000 empty lists:
list_0, ... , list_999 = [], ... , []
which seems quite tedious if one were to use the top approach.
In such a case, and my question, is it okay to use globals()
, such as:
for i in range(1000):
globals()["list_%s" % i] = []
I haven't really seen such method at SO for many times, and started to wonder if it is because of some downsides I'm not aware of.
I've googled with different keywords, and did find some use cases in second answer of this post, and so on, but ended up with no fruitful result.
Any insight would be highly appreciated. Thanks!