How do I Pythonically generate a hash table / hashmap?

Viewed 70

I am trying to generate a 2d dictionary (hash table?) with characters A through J as keys, mapping to dictionaries mapping the values 1 through 20 to one of ten lists of random sequences of the same values.

I created lists of characters thus:

values = list(range(1, 21))
rand_vals_1 = copy.copy(values)
random.shuffle(rand_vals_1)
# repeated for rand_vals_2 - rand_vals_10

I know how to create a dictionary to map values to each random sequence thus:

values_iterator = zip(values, rand_vals_1)
values_1_dict = dict(values_iterator)
# and so on for random sequences `rand_vals_2` through `rand_vals_10`

I know how to create the [hash table] thus:

mappings = {'A': values_1_dict, ..., 'J': values_10_dict}

My question is, what would be a more Pythonic method to create mappings using list comprehension?

0 Answers
Related