Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 printing a list contents without brackets in a print statement
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
use join
>>> mlist = ['one', 'two', 'five', 'six']
>>> print(f"{' '.join(mlist)}")
one two five six

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  capture print statement written in Stored Procedure in SQL Server brijeshkumar_77 0 93 Feb-18-2020, 03:22 AM
Last Post: brijeshkumar_77
  Printing output without print usage susmith552 1 145 Feb-07-2020, 07:52 PM
Last Post: Clunk_Head
  Trying to print an uneven list to a even table Mike2607 6 253 Nov-19-2019, 06:14 AM
Last Post: perfringo
  Dictionnary brackets issue Reldaing 1 124 Nov-10-2019, 11:54 PM
Last Post: ichabod801
  print all method and property of list object engmoh 4 368 Oct-26-2019, 05:33 PM
Last Post: engmoh
  Embedding return in a print statement Tapster 3 180 Oct-07-2019, 03:10 PM
Last Post: Tapster
  Quotes and variables in print statement Mark17 4 283 Sep-13-2019, 04:07 PM
Last Post: Mark17
  Passing print output into another print statement Pleiades 6 284 Sep-08-2019, 02:37 PM
Last Post: Pleiades
  list comprehension : print column as row pyseeker 4 438 Sep-05-2019, 05:40 AM
Last Post: pyseeker
  How to print data in bracket in list in one side. phob0s 2 346 Jul-23-2019, 08:00 AM
Last Post: phob0s

Forum Jump:

Users browsing this thread: 1 Guest(s)