Python "best formatting practice" for lists, dictionary, etc Python "best formatting practice" for lists, dictionary, etc python python

Python "best formatting practice" for lists, dictionary, etc


My preferred way is:

something = {'foo': 'bar',             'foo2': 'bar2',             'foo3': 'bar3',             ...             'fooN': 'barN'}


aaronasterling's indentation style is what I prefer. This, and several other styles are explained in another SO Question. Especially Lennart Regebro's answer gave a nice overview.

But this style was the one most voted for:

my_dictionary = {    1: 'something',    2: 'some other thing',}


According to the PEP8 style guide there are two ways to format a dictionary:

mydict = {    'key': 'value',    'key': 'value',    ...    }

OR

mydict = {    'key': 'value',    'key': 'value',    ...}

If you want to conform to PEP8 I would say anything else is technically wrong.