0

I have a few variables from which I want to create a dictionary. This is done in a loop, and will later be used for a list of such dictionaries, for example to create a pandas.DataFrame. For example,

res = []
for item in my_collection:
    foo = foo_function(item)
    bar = bar_funtion(item)
    baz = baz_function(item)
    res.append(dict(foo=foo, bar=bar, baz=baz))

What I'm asking is in fact how to create the dictionary more succinctly, by only providing the variable names. something like make_dict(foo,bar,baz)

Amir Rosenfeld
  • 331
  • 2
  • 12

0 Answers0