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
  Print text with big font and style tomtom 6 20,714 Aug-13-2024, 07:26 AM
Last Post: yazistilleriio
  Print the next 3 lines knob 3 1,147 May-22-2024, 12:26 PM
Last Post: andraee
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 4,381 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 2,910 May-22-2023, 10:39 PM
Last Post: ICanIBB
  How do you get Python to print just one value in a list? 357mag 3 2,112 May-17-2023, 09:52 PM
Last Post: rob101
  Start print a text after open an async task via button Nietzsche 0 1,170 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Finding combinations of list of items (30 or so) LynnS 1 1,516 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  Saving the print result in a text file Calli 8 4,142 Sep-25-2022, 06:38 PM
Last Post: snippsat
  For Word, Count in List (Counts.Items()) new_coder_231013 6 6,829 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get list of exactly 10 items? Mark17 1 3,677 May-26-2022, 01:37 PM
Last Post: Mark17

Forum Jump:

User Panel Messages

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