Python Forum
printing a list contents without brackets in a print statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing a list contents without brackets in a print statement
#1
Using python 3 I am trying the following code. I would like to change the last two lines of the code where the print(*uninvlist, sep=", " is in the directly above that lines print statement. That way its all in one line. How would I code that where the sep wouldn't error it out. It works fine as a separate line. Im just doing some learning exercises in a book and would like to go a little further with it.

uninvlist = [] #created a empty list that I can add too
uninvlist.insert (0, uninvited_guest.title()) #inserting the first one
uninvlist.insert (-1, seconduniv.title())
uninvlist.insert (-1, thirduniv.title())
uninvlist.insert (-1, forthuniv.title())
uninvlist.sort() #sorts the list
#uninvlist = (uninvited_guest) + (firstuniv) + (seconduniv) + (thirduniv) + (forthuniv) #runs it as one word
#messulist = uninvlist #adding the list to a message
print('\nThe entire uninvited list for the party is as follows:')# + (univmessage)) 
print(*uninvlist, sep=", ") # removed the [] had to put on a separate line for now
Reply
#2
use join
example:
>>> mlist = ['one', 'two', 'five', 'six']
>>> print(f"{' '.join(mlist)}")
one two five six
>>>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do you get Python to print just one value in a list? 357mag 3 967 May-17-2023, 09:52 PM
Last Post: rob101
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 1,451 Sep-03-2022, 11:21 PM
Last Post: Winfried
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,601 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
Question Printing through list.. again jesse68 2 1,109 Apr-16-2022, 03:24 PM
Last Post: jesse68
  Print List to Terminal DaveG 2 1,408 Apr-02-2022, 11:25 AM
Last Post: perfringo
  Reading list items without brackets and quotes jesse68 6 4,518 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Data pulled from SQL comes in brackets nickzsche 3 2,546 Jan-04-2022, 03:39 PM
Last Post: ibreeden
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 2,167 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
  Change a list to integer so I can use IF statement buckssg 3 2,194 Sep-21-2021, 02:58 AM
Last Post: bowlofred
  printing out the contents aftre subprocess.call() Rakshan 3 2,701 Jul-30-2021, 08:27 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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