what is the correct way :
def my_func():
return {'key1': val1, 'key2': val2}
or
def my_func():
return
{
'key1': val1,
'key2': val2
}
The second way seems more readable (especially when there is a lot of keys values, or nested objects) but I’m not sure the blank after return will work in every case
edit:
After some answers, I would suggest this :
def my_func():
return {'key1': val1,
'key2': val2}
which seems to be the most consistent
For short dictionaries, the first one is OK, the second one won’t work as expected (returns
None). For longer ones, I would prefer something like