I want to achieve the same result of
{i: i+1 for i in range(4)} # {0: 1, 1: 2, 2: 3, 3: 4}
But dynamically generate key: value
part with myfunc(i)
, how do I do that?
Functions that return {i: i+1}
or (i, i+1)
won't work:
{{i: i+1} for i in range(4)} # TypeError: unhashable type: 'dict'