Don't use map()
. Use a list comprehension and itertools.product()
:
from itertools import product
[{(i, j): 'G{}{}'.format(i, j)} for i, j in product(range(l), repeat=2)]
or using your function for the left-hand expression:
[add_force_coupling(i, j, 'G{}{}'.format(i, j))
for i, j in product(range(l), repeat=2)]
It does strike me that you are looking to build one dictionary here; a dict comprehension could do that:
{(i, j): 'G{}{}'.format(i, j) for i, j in product(range(l), repeat=2)}
Here you can address each item with result[i, j]
.
but given the indices, a nested list would be a more efficient storage mechanism for the data:
[['G{}{}'.format(i, j) for j in range(l)] for i in range(l)]
and address results with
result[i][j]