I quite regularly want to create a dictionary where keys are variable names. For example if I have variables a and b I want to generate: {"a":a, "b":b} (typically to return data at the end of a function).
Are there any (ideally built in) ways in python to do this automatically? i.e to have a function such that create_dictionary(a,b) returns {"a":a, "b":b}
"a":adoesn't make much sense,ais going to get replaced by its value. - Dimitris Fasarakis Hilliardlocals()), I think this is very rarely a good solution. In the example you gave (returning multiple values from a function), consider returning anamedtuplefrom the collections module. - flornquake{"a":a, "b":b}where the variable names in your views are the same as in the templates. - Daniel Holmes