Python Forum
Print list items on separate lines with additional text
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print list items on separate lines with additional text
#1
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.

Output:
Incorrect name value - A name must be placed on all orders. Please add a name. Address included - An address must be included on all orders. Please add an address. Telephone number present - A telephone number must be present.  Please add a telephone number. Move completed - Move is completed.  No further action required.
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)
Reply
#2
Change '; ' to '\n' in the next to last line.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 12 589 Apr-12-2024, 11:51 AM
Last Post: deanhystad
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 177 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,319 May-22-2023, 10:39 PM
Last Post: ICanIBB
  How do you get Python to print just one value in a list? 357mag 3 1,006 May-17-2023, 09:52 PM
Last Post: rob101
  Start print a text after open an async task via button Nietzsche 0 698 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Finding combinations of list of items (30 or so) LynnS 1 867 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  Saving the print result in a text file Calli 8 1,781 Sep-25-2022, 06:38 PM
Last Post: snippsat
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,568 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get list of exactly 10 items? Mark17 1 2,489 May-26-2022, 01:37 PM
Last Post: Mark17
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,361 May-17-2022, 07:49 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020