5

when coding a very long list in python, is it better to fit several items on each line or should I limit it to 1 per line? 99% of the time I would go with style2 below but I have 5 lists each about the same length as the one below and it seems like too many lines. any advice would be appreciated.

for example:

style1 = [
    'Email:', 'SSN:', 'Address:', 'Home Phone:',
    'Mobile Phone: ', 'DOB:', 'Date of Surgery:',
    'Date of Service:', 'Facility of Service:', 'Clinic Number:',
    'Employer:', 'Work Phone: ', 'Fax: ', 'Type:', 'IPA:',
    'Health Plan:', 'ID #:', 'Claims Address:', 'Group #:',
    'Claim # / PO #:', 'Phone:', 'Fax:', 'Contact',
    'Adjuster Email', 'Util Review Phone', 'Util Review Fax',
    'Doctor:', 'NPI #: ', 'Date of Injury: ', 'Body Parts:',
    'Body Part Side:', 'Gender:', 'Diagnosis:', 'Diagnosis 2:',
    'Procedure:'
    ]

style2 = [
    'Email:',
    'SSN:',
    'Address:',
    'Home Phone:',
    'Mobile Phone: ',
    'DOB:',
    'Date of Surgery:',
    'Date of Service:',
    'Facility of Service:',
    'Clinic Number:',
    'Employer:',
    'Work Phone: ',
    'Fax: ',
    'Type:',
    'IPA:',
    'Health Plan:',
    'ID #:',
    'Claims Address:',
    'Group #:',
    'Claim # / PO #:',
    'Phone:',
    'Fax:',
    'Contact',
    'Adjuster Email',
    'Util Review Phone',
    'Util Review Fax',
    'Doctor:',
    'NPI #: ',
    'Date of Injury: ',
    'Body Parts:',
    'Body Part Side:',
    'Gender:',
    'Diagnosis:',
    'Diagnosis 2:',
    'Procedure:'
    ]
rob
  • 71

2 Answers2

7

The PEP 8 Python style guide shows lists in the form:

my_list = [
    1, 2, 3,
    4, 5, 6,
    ]

In the indentation section of the pep https://www.python.org/dev/peps/pep-0008/#indentation

For this reason I would say style 1 (ensuring not to violate the line length rules).

Joe Reid
  • 111
4

Personally, I'm using style2. Because its very easy for adding new item to list. Also with style2 you can easly delete item with deleting row. But its difficult on style1.