If i have a variable number of arrays, how do I initialize/work on them?
x = int(input())
for i in range(x):
dict_i = {}
If i have a variable number of arrays, how do I initialize/work on them?
x = int(input())
for i in range(x):
dict_i = {}
This would generate a list of dictionaries. You should be able to access them afterwards based on index.
x = int(input())
dictionaries = []
for i in range(x):
dictionaries.append(dict())
print(dictionaries)
Simplest solution would be to use globals
and setattr
:
x = int(input())
for i in range(x):
globals()[f"dict_{i}"] = {}
But I can't think of why you would want to do this at all.