I need to build a data structure like this one:
{
key: {k: v for k in range(fixed_small_number)}
for key in range(fixed_large_number)
}
The thing is I'm building it in an "eclectic" way, where every time get one more item to put in a random k for a random key, i.e. I need random-access, and I need the inner dict to be mutable.
So my question is divided into two:
The recommended type for the outer dict.
The recommended type for the inner dict.
the "best" solution for me would be an array of mutable namedtuples, only this doesn't exist.
I could use a list of namedtuples, and then recreate each one with the new data, but that sounds super-wasteful with the lists not being random-access-efficient and all the rewrites of the same data.
Is there some magical new structure I'm not aware of?
EDIT: example of usage:
for key, k, v in [('a', 1, 2), ('b', 1, 3), ('a', 2, 1), ('a', 3, 1), ('b', 3, 1) ...]:
my_structre[key][k] = v
EDIT2:
it turns out that lists actually DO support random access