I'm trying to map two arrays together to a list of dictionaries. Like this:
a_list = [1, 2, 3]
b_list = ["a", "b", "c"]
d = [{"key1": a, "key2": b} for a in a_list for b in b_list]
>> [{"key1": 1, "key2": "a"}, {"key1": 2, "key2": "b"}, {"key1": 3, "key2": "c"}]
However, this gives:
[{"key1": 1, "key2": "a"}, {"key1": 1, "key2": "b"}, [...] {"key1": 3, "key2": "b"}, {"key1": 3, "key2": "c"}]
I've tried replacing the second for
with both and
and a ,
, as well as moving parts off the code into parentheses back and forth.