You cannot use list as a key to a dictionary, as it is modified.
You can convert list to tuple :
>>> count = (1, 0, 0, 2, 0) >>> bins = [[2.0, 3.0], [3.0, 4.0], [4.0, 5.0], [5.0, 6.0], [6.0, 7.0], [7.0, 8.0]] >>> {tuple(key): value for (key, value) in zip(bins, count)} {(4.0, 5.0): 0, (3.0, 4.0): 0, (5.0, 6.0): 2, (2.0, 3.0): 1, (6.0, 7.0): 0}
If you want to serialize in json , the keys must be strings. Instead, you can convert cells to strings:
>>> {str(key): value for (key, value) in zip(bins, count)} {'[2.0, 3.0]': 1, '[4.0, 5.0]': 0, '[6.0, 7.0]': 0, '[5.0, 6.0]': 2, '[3.0, 4.0]': 0} >>> import json >>> json.dumps(_) '{"[2.0, 3.0]": 1, "[4.0, 5.0]": 0, "[6.0, 7.0]": 0, "[5.0, 6.0]": 2, "[3.0, 4.0]": 0}'
Alternatively, just serialize the pairs and make the dictionary on the receiving side:
>>> zip(bins, count) [([2.0, 3.0], 1), ([3.0, 4.0], 0), ([4.0, 5.0], 0), ([5.0, 6.0], 2), ([6.0, 7.0], 0)] >>> import json >>> json.dumps(_) '[[[2.0, 3.0], 1], [[3.0, 4.0], 0], [[4.0, 5.0], 0], [[5.0, 6.0], 2], [[6.0, 7.0], 0]]'