Print list items on separate lines with additional text - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Print list items on separate lines with additional text (/thread-1532.html) |
Print list items on separate lines with additional text - DBS - Jan-11-2017 Hello, I have some code that reads the columns of a csv and if the column value is True, print the list as a string, which I have working. I now need to print each on a separate line and add text based on which element is present in the failed_validation_lst, such as in the output below. Any help is greatly appreciated.
failed_validation_lst = [] for column, val in enumerate(row): if headers[column] in ['Incorrect name value', 'Address included', 'Telephone number present', 'Move completed'] and val == 'True': failed_validation_lst.append(headers[column]) failed_validation_string = '; '.join(failed_validation_lst) print(failed_validation_string) RE: Print list items on separate lines with additional text - ichabod801 - Jan-11-2017 Change '; ' to '\n' in the next to last line. RE: Print list items on separate lines with additional text - DBS - Jan-11-2017 Thanks. Any suggestions on pairing the messages with column headers in the list? Such as if the list only contains two of the elements and I want to pair the messages in the output to those elements that exist in the list? |